Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface SmartHomeApp

Hierarchy

  • ServiceBaseApp
    • SmartHomeApp

Properties

handler

Optional jwt

Optional key

key: undefined | string

Methods

onDisconnect

  • Defines a function that will run when a DISCONNECT request is received.

    example
    
    const app = smarthome();
    app.onDisconnect((body, headers) => {
      // User unlinked their account, stop reporting state for user
      return {}
    })
    
    example
    
    const app = smarthome();
    app.onDisconnect((body, headers) => {
      // User unlinked their account, stop reporting state for user
      return {}
    })
    

    Parameters

    Returns this

onExecute

  • Defines a function that will run when an EXECUTE request is received.

    example
    
    const app = smarthome();
    app.onExecute((body, headers) => {
      return {
        requestId: 'ff36...',
        payload: {
          ...
        }
      }
    })
    
    example
    
    const app = smarthome();
    app.onExecute((body, headers) => {
      return {
        requestId: 'ff36...',
        payload: {
          ...
        }
      }
    })
    

    Parameters

    Returns this

onQuery

  • Defines a function that will run when a QUERY request is received.

    example
    
    const app = smarthome();
    app.onQuery((body, headers) => {
      return {
        requestId: 'ff36...',
        payload: {
          ...
        }
      }
    })
    
    example
    
    const app = smarthome();
    app.onQuery((body, headers) => {
      return {
        requestId: 'ff36...',
        payload: {
          ...
        }
      }
    })
    

    Parameters

    Returns this

onSync

  • Defines a function that will run when a SYNC request is received.

    example
    
    const app = smarthome();
    app.onSync((body, headers) => {
      return {
        requestId: 'ff36...',
        payload: {
          ...
        }
      }
    })
    
    example
    
    const app = smarthome();
    app.onSync((body, headers) => {
      return {
        requestId: 'ff36...',
        payload: {
          ...
        }
      }
    })
    

    Parameters

    Returns this

reportState

  • Reports the current state of a device or set of devices to the home graph. This may be done if the state of the device was changed locally, like a light turning on through a light switch.

    When calling this function, a JWT (JSON Web Token) needs to be provided as an option in the constructor.

    example
    const app = smarthome({
      jwt: require('./jwt.json');
    });
    
    const reportState = () => {
      app.reportState({
        requestId: '123ABC',
        agentUserId: 'user-123',
        payload: {
          devices: {
            states: {
              "light-123": {
                on: true
              }
            }
          }
        }
      })
      .then((res) => {
        // Report state was successful
      })
      .catch((res) => {
        // Report state failed
      })
    };
    

    When calling this function, a JWT (JSON Web Token) needs to be provided as an option in the constructor.

    example
    const app = smarthome({
      jwt: require('./jwt.json');
    });
    
    const reportState = () => {
      app.reportState({
        requestId: '123ABC',
        agentUserId: 'user-123',
        payload: {
          devices: {
            states: {
              "light-123": {
                on: true
              }
            }
          }
        }
      })
      .then((res) => {
        // Report state was successful
      })
      .catch((res) => {
        // Report state failed
      })
    };
    
    example
    const app = smarthome({
      jwt: require('./jwt.json');
    });
    
    const reportState = () => {
      app.reportState({
        requestId: '123ABC',
        agentUserId: 'user-123',
        payload: {
          devices: {
            states: {
              "light-123": {
                on: true
              }
            }
          }
        }
      })
      .then((res) => {
        // Report state was successful
      })
      .catch((res) => {
        // Report state failed
      })
    };
    

    Parameters

    Returns Promise<string>

requestSync

  • requestSync(agentUserId: string): Promise<string>
  • Sends a request to the home graph to send a new SYNC request. This should be called when a device is added or removed for a given user id.

    When calling this function, an API key needs to be provided as an option in the constructor. See https://developers.google.com/actions/smarthome/create-app#request-sync to learn more.

    example
    
    const app = smarthome({
      key: "123ABC"
    });
    
    const addNewDevice = () => {
      app.requestSync('user-123')
        .then((res) => {
          // Request sync was successful
        })
        .catch((res) => {
          // Request sync failed
        })
    }
    
    // When request sync is called, a SYNC
    // intent will be received soon after.
    app.onSync(body => {
      // ...
    })
    

    When calling this function, an API key needs to be provided as an option in the constructor. See https://developers.google.com/actions/smarthome/create-app#request-sync to learn more.

    example
    
    const app = smarthome({
      key: "123ABC"
    });
    
    const addNewDevice = () => {
      app.requestSync('user-123')
        .then((res) => {
          // Request sync was successful
        })
        .catch((res) => {
          // Request sync failed
        })
    }
    
    // When request sync is called, a SYNC
    // intent will be received soon after.
    app.onSync(body => {
      // ...
    })
    
    example
    
    const app = smarthome({
      key: "123ABC"
    });
    
    const addNewDevice = () => {
      app.requestSync('user-123')
        .then((res) => {
          // Request sync was successful
        })
        .catch((res) => {
          // Request sync failed
        })
    }
    
    // When request sync is called, a SYNC
    // intent will be received soon after.
    app.onSync(body => {
      // ...
    })
    

    Parameters

    • agentUserId: string

      The user identifier.

    Returns Promise<string>

Generated using TypeDoc