Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface SmartHomeApp

Hierarchy

  • ServiceBaseApp
    • SmartHomeApp

Properties

handler

Optional jwt

Optional key

key: undefined | string

Methods

onDisconnect

onExecute

onQuery

onSync

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
      })
    };

    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 => {
      // ...
    })

    Parameters

    • agentUserId: string

      The user identifier.

    Returns Promise<string>

Generated using TypeDoc