google-home / smart-home-nodejs

A sample of the Smart Home device control APIs in Actions on Google
Apache License 2.0
888 stars 289 forks source link

404 Error with Report State #506

Closed OsenLiu closed 4 years ago

OsenLiu commented 4 years ago

I tried to deploy smart-home-nodejs with demo user. Sync is no problem and agentUserId is 1234.

Request {
  "inputs": [
    {
      "intent": "action.devices.SYNC"
    }
  ],
  "requestId": "17717872861611125484"
}
Headers {
  "content-type": "application/json;charset=UTF-8",
  "google-assistant-api-version": "v1",
  "authorization": "Bearer 123access",
  "host": "wwmltd.asuscomm.com",
  "content-length": "80",
  "connection": "keep-alive",
  "user-agent": "Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)",
  "accept-encoding": "gzip,deflate,br"
}
nop smartHome onSync
Response {
  "status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "requestId": "17717872861611125484",
    "payload": {
      "agentUserId": "1234",
      "devices": [
        {
          "id": "1s3y",
          "type": "action.devices.types.CAMERA",
          "traits": [
            "action.devices.traits.CameraStream"
          ],
          "name": {
            "defaultNames": [
              "Smart Camera"
            ],
            "name": "Smart Camera",
            "nicknames": [
              "office camera"
            ]
          },
          "deviceInfo": {
            "manufacturer": "L",
            "model": "L",
            "hwVersion": "1.0.0",
            "swVersion": "2.0.0"
          },
          "willReportState": true,
          "attributes": {
            "cameraStreamSupportedProtocols": [
              "hls",
              "dash"
            ],
            "cameraStreamNeedDrmEncryption": false,
            "cameraStreamNeedAuthToken": false
          }
        },
        {
          "id": "1yxw",
          "type": "action.devices.types.CAMERA",
          "traits": [
            "action.devices.traits.CameraStream"
          ],
          "name": {
            "defaultNames": [
              "Smart Camera"
            ],
            "name": "channel 3",
            "nicknames": [
              "channel 3"
            ]
          },
          "deviceInfo": {
            "manufacturer": "L",
            "model": "L",
            "hwVersion": "1.0.0",
            "swVersion": "2.0.0"
          },
          "willReportState": true,
          "attributes": {
            "cameraStreamNeedAuthToken": false,
            "cameraStreamSupportedProtocols": [
              "hls",
              "dash"
            ],
            "cameraStreamNeedDrmEncryption": false
          }
        },
        {
          "id": "259",
          "type": "action.devices.types.LIGHT",
          "traits": [
            "action.devices.traits.Brightness",
            "action.devices.traits.OnOff",
            "action.devices.traits.ColorSetting"
          ],
          "name": {
            "defaultNames": [
              "Smart RGB Light"
            ],
            "name": "Smart RGB Light",
            "nicknames": [
              "table lamp"
            ]
          },
          "deviceInfo": {
            "manufacturer": "L",
            "model": "L",
            "hwVersion": "1.0.0",
            "swVersion": "2.0.0"
          },
          "willReportState": true,
          "attributes": {
            "colorModel": "rgb"
          }
        },
        {
          "id": "8k1",
          "type": "action.devices.types.CAMERA",
          "traits": [
            "action.devices.traits.CameraStream"
          ],
          "name": {
            "defaultNames": [
              "Smart Camera"
            ],
            "name": "channel 4",
            "nicknames": [
              "channel 4"
            ]
          },
          "deviceInfo": {
            "manufacturer": "L",
            "model": "L",
            "hwVersion": "1.0.0",
            "swVersion": "2.0.0"
          },
          "willReportState": true,
          "attributes": {
            "cameraStreamSupportedProtocols": [
              "hls",
              "dash"
            ],
            "cameraStreamNeedDrmEncryption": false,
            "cameraStreamNeedAuthToken": false
          }
        },
        {
          "id": "kd5",
          "type": "action.devices.types.CAMERA",
          "traits": [
            "action.devices.traits.CameraStream"
          ],
          "name": {
            "defaultNames": [
              "Smart Camera"
            ],
            "name": "channel 2",
            "nicknames": [
              "channel 2"
            ]
          },
          "deviceInfo": {
            "manufacturer": "L",
            "model": "L",
            "hwVersion": "1.0.0",
            "swVersion": "2.0.0"
          },
          "willReportState": true,
          "attributes": {
            "cameraStreamSupportedProtocols": [
              "hls",
              "dash"
            ],
            "cameraStreamNeedDrmEncryption": false,
            "cameraStreamNeedAuthToken": false
          }
        }
      ]
    }
  }
}
POST /smarthome 200 1956.796 ms - 2203

But I got 404 error to send reportState. What have i done wrong?

  var data = {
    agentUserId: userID,
    requestId: uuidv1(),
    payload: {
      devices: {
        states: {
          [deviceId]: states,
        },
      },
    },
  };
  console.log(JSON.stringify(data));
  return await app.reportState(data);
{"agentUserId":"1234","requestId":"1a5270c0-7fb5-11ea-8be9-87327eed7e32","payload":{"devices":{"states":{"1s3y":{"online":true}}}}}
{"agentUserId":"1234","requestId":"1a5d1f20-7fb5-11ea-8be9-87327eed7e32","payload":{"devices":{"states":{"1yxw":{"online":true}}}}}
{"agentUserId":"1234","requestId":"1a708010-7fb5-11ea-8be9-87327eed7e32","payload":{"devices":{"states":{"259":{"online":true,"on":true,"brightness":90,"color":{"spectrumRgb":0}}}}}}
{"agentUserId":"1234","requestId":"1a711c50-7fb5-11ea-8be9-87327eed7e32","payload":{"devices":{"states":{"kd5":{"online":true}}}}}
{"agentUserId":"1234","requestId":"1a71b890-7fb5-11ea-8be9-87327eed7e32","payload":{"devices":{"states":{"8k1":{"online":true}}}}}
(node:4844) UnhandledPromiseRejectionWarning: {
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND"
  }
}

(node:4844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4844) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:4844) UnhandledPromiseRejectionWarning: {
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND"
  }
}

(node:4844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4844) UnhandledPromiseRejectionWarning: {
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND"
  }
}

(node:4844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:4844) UnhandledPromiseRejectionWarning: {
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND"
  }
}

(node:4844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:4844) UnhandledPromiseRejectionWarning: {
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND"
  }
}

(node:4844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)
Fleker commented 4 years ago

Did you download the service account key in the right location?