google-home / smart-home-nodejs

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

Example not working with Simulator and `/smarthome/update` returns 500 #530

Closed unsigned6 closed 3 years ago

unsigned6 commented 3 years ago

Hello and thanks a lot for this guidance.

Tried to run an example using README. I deployed to firebase, but when starting a test on Simulator, it gives me "We're sorry, but something went wrong. Please try again."

On the client of displayed app devices are adding successfully. Request from to change device state returns code 500 with payload: {reportStateError: "Requested entity was not found."}

Should I make any other changes for example source code before deployment? Or maybe you have any other ideas

proppy commented 3 years ago

There was an issue in the frontend with cascading call to /update that was fixed with https://github.com/actions-on-google/smart-home-frontend/commit/b1045c4cd42e733fc411d2192827e5948aca3abf

Can you confirm if it fixes the issue for you?

unsigned6 commented 3 years ago

Looks like I have these changes already. Used latest source code from master

proppy commented 3 years ago

@unsigned6 did you follow the instruction to link your smart home actions in the Google Home app as described here: https://github.com/actions-on-google/smart-home-nodejs#set-up-account-linking

Are you able to control the device from the Google Home app or the Assistant app?

unsigned6 commented 3 years ago

Yes, I've setup fullfillemnt and account linking. Test of Assistant app gives me: "We're sorry, but something went wrong. Please try again."

It looks like an issue with reportState. When checked logs in firebase it actually show an error for devicesManager endpoint:

deviceManager
error reporting device state to homegraph: {"error":{"status":"NOT_FOUND","message":"Requested entity was not found.","code":404}}

Also checked another similar tutorial https://codelabs.developers.google.com/codelabs/smarthome-local#2 where have same issue, where error happens in requestsync method which was related to gaxios library used by actions-on-google. Will give also this one because it has a more detailed stacktrace

requestsync
{ Error: Requested entity was not found.
    at Gaxios._request (/workspace/node_modules/googleapis/node_modules/gaxios/build/src/gaxios.js:85:23)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  response:
   { config:
      { url: 'https://homegraph.googleapis.com/v1/devices:requestSync',
        method: 'POST',...
unsigned6 commented 3 years ago

 Also after redirect on my phone, I have 404 error from firebase:  It tries to redirect with such a route

 /login?response_url=https%3A%2F%2Foauth-redirect.googleusercontent.com%2Fr%2Fassistent-test-c6dde%3Fcode%3Dxxxxxx%26state%3DABdO3MV_8yO6fnobQEbJofD0wR_haRPvzTXNWbdzsf85eZqlAbrrSzQDHBT6_xlVrKUKsl8o7sM7TzH1yD-gQFS5Ds_Bqs7c0K0_C0uT79lC_kWmR5VSHsFqPkj5z9zPv1PxqdnXMBjkIdVFt67aiWaKKw3l5aDjqxctcueC694dd9lc92pqABJN-orVx9P6Kq3-pMD3FPwY0fVAu98bSjEOETXOXdeRdZYpztlSDBXyQ6560EFdZ2nqLRPcv1UMBMoFqJiu8jqN1KmVC7QP4qLHdbCfA8uY8xlJIxGlNuECjjK_dTlxw9e68YYbZP-nBUJdE0wl9ZW5oINobtCi_HDfUYChcjzElZ68CvsSMKHiSt69dqXETTr3SN4fzTMheOPfli0va53gJG7yuNmJnR3uTJnZVphC6d66LRwOX68loKdJoRxoTyaCX--swZzxonZWFRePLEDNdMQlkfPZ9HC-6eaFFUS0mOI6I-Kqy9ZAc6qeKa2XBTkIS4pv63u0GB-fiyrh-ThRWu72cGMeZPj_rxDgk-3Rjo7-BMK7yKnhUReZ6Z7S72BPfbQj5Z4sadkrGw2DacNmgT9AghDp8ruHsLB1G4ryj7I2Sp-foTSlQN4-WAAAIAUtTfWeaUVfj1AQse2pm5alTvJ-GdaViC7jB6crKRuZlQ 

 and in firebase functions logs it seems this redirect happens twice: first time to this url, second redirectUrl get undefined:  

 app.post('/login', async (req, res) => {
  functions.logger.debug('/login', req.query);
  // Here, you should validate the user account.
  // In this sample, we do not do that.
  const responseUrl = decodeURIComponent(req.body.response_url as string);
  functions.logger.debug('redirect:', responseUrl);
  return res.redirect(responseUrl);
});
proppy commented 3 years ago

@unsigned6 did you get any error when deploying the firebase hosting configuration with the rewrites directives? https://github.com/actions-on-google/smart-home-nodejs/blob/master/firebase.json#L13

It should happen automatically when running npm run deploy.

unsigned6 commented 3 years ago

@proppy No, any errors. Here is output


> smart-home-app-sample@0.0.1 deploy /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs
> firebase deploy

⚠  functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.

=== Deploying to 'assistent-test-c6dde'...

i  deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint

> smart-home-app-sample@0.0.1 lint /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs
> gts lint

version: 12
Running command: npm --prefix "$RESOURCE_DIR" run build

> smart-home-app-sample@0.0.1 build /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs
> npm run compile && cp src/*.json build/

> smart-home-app-sample@0.0.1 compile /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs
> tsc

✔  functions: Finished running predeploy script.
Running command: npm --prefix "$RESOURCE_DIR"/.. run test

> smart-home-frontend@0.0.1 test /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs/frontend
> npm run lint

> smart-home-frontend@0.0.1 lint /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs/frontend
> eslint ./src

Running command: npm --prefix "$RESOURCE_DIR"/.. run build

> smart-home-frontend@0.0.1 build /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs/frontend
> rollup -c rollup.config.js

src/my-app.js → public...
(!) If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.
> smart-home-frontend@0.0.1 build /Users/yuriivlasiuk/Projects/2smart/cloud/smart-home-nodejs/frontend
> rollup -c rollup.config.js

src/my-app.js → public...
(!) If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.
created public in 1.9s
✔  hosting: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing . directory for uploading...
i  functions: packaged . (773.33 KB) for uploading
✔  functions: . folder uploaded successfully
i  hosting[assistent-test-c6dde]: beginning deploy...
i  hosting[assistent-test-c6dde]: found 2 files in frontend/public
✔  hosting[assistent-test-c6dde]: file upload complete
i  functions: updating Node.js 12 function authProvider(us-central1)...
i  functions: updating Node.js 12 function deviceManager(us-central1)...
i  functions: updating Node.js 12 function fulfillment(us-central1)...
✔  functions[deviceManager(us-central1)]: Successful update operation.
✔  functions[authProvider(us-central1)]: Successful update operation.
✔  functions[fulfillment(us-central1)]: Successful update operation.
i  hosting[assistent-test-c6dde]: finalizing version...
✔  hosting[assistent-test-c6dde]: version finalized
i  hosting[assistent-test-c6dde]: releasing new version...
✔  hosting[assistent-test-c6dde]: release complete

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/assistent-test-c6dde/overview
Hosting URL: https://assistent-test-c6dde.web.app
proppy commented 3 years ago

And to you see the login form when visiting https://assistent-test-c6dde.web.app/login?

unsigned6 commented 3 years ago

@proppy just a button "Link this service to Google" I think this comes from an auth-provider.ts.

unsigned6 commented 3 years ago

I've mentioned that there are the different field name and body object key in login form and /login handler (responseurl & response_url): in form

<input type="hidden" name="responseurl" value="${req.query.responseurl}" />

in handler

app.post('/login', async (req, res) => {
...
  const responseUrl = decodeURIComponent(req.body.response_url as string);

Could this be a reason?

unsigned6 commented 3 years ago

Yeah that's it. After change responseurl => response_url in form I've synced the device in my Google Home app.

unsigned6 commented 3 years ago

Is it possible now to get control by google assistant commands? When trying this in the developer console in Test, I've got for this actions: "We're sorry, but something went wrong. Please try again." after calling of invocation name

proppy commented 3 years ago

re https://github.com/actions-on-google/smart-home-nodejs/issues/530#issuecomment-763592064: @unsigned6 that sounds related to https://github.com/actions-on-google/smart-home-nodejs/issues/527, will push the fix we already have upstream for this shortly.

re https://github.com/actions-on-google/smart-home-nodejs/issues/530#issuecomment-763604402: do you also have this issue when trying from a phone from the home app, the assistant app or an assistant device ?

proppy commented 3 years ago

pushed https://github.com/actions-on-google/smart-home-nodejs/commit/709d2007f6d9a57620af1c8a10c81e5522d5c79b

unsigned6 commented 3 years ago

re #530 (comment): @unsigned6 that sounds related to #527, will push the fix we already have upstream for this shortly.

re #530 (comment): do you also have this issue when trying from a phone from the home app, the assistant app or an assistant device ?

From the phone, I've seen the device in the Google Home app. Not able to check with google assistant (for some reason it not trigger my action with an invocation name). But maybe it needs to deploy my google actions.

proppy commented 3 years ago

Not able to check with google assistant (for some reason it not trigger my action with an invocation name).

You don't need to trigger it with an invocation name, you just need to issue the command directly, i.e: Turn on the light.

I've seen the device in the Google Home app

Are you able to control it using the touch control as shown in https://developers.google.com/assistant/smarthome/develop/touch-controls#google_home_app ?

unsigned6 commented 3 years ago

you just need to issue the command directly

will try tomorrow when my google home arrive

Are you able to control it using the touch control as shown in https://developers.google.com/assistant/smarthome/develop/touch-controls#google_home_app ?

in Google Home app - yes. was able to control mocked light

proppy commented 3 years ago

will try tomorrow when y google home arrive

You should also be able to issue voice comment from the Google Assistant app on your phone.

unsigned6 commented 3 years ago

Yeah, but not with iPhone yet.

To summarize - the main reason for the error was incomplete account linking. Maybe it makes sense to handle it somehow to show that the account is not linked.

Closing this issue.