Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiError when trying to setLightState on fresh bridge paired light #197

Open
VonOx opened this issue May 7, 2021 · 5 comments
Open

ApiError when trying to setLightState on fresh bridge paired light #197

VonOx opened this issue May 7, 2021 · 5 comments

Comments

@VonOx
Copy link

VonOx commented May 7, 2021

Hi

I'm contributor to open-source project GladysAssistant
We use this lib in our Philips Hue services ( in version 4.0.9 ). Thank you BTW !

We have some weird behavior, newly bridge paired light can't be controlled without a restart.

See gladys log

2021-05-07T10:12:53+0200 <debug> light.setValue.js:17 (PhilipsHueLightHandler.setValue) Changing state of light philips-hue-light:001788286ece:10 with value = 0
2021-05-07T10:12:53+0200 <warn> scene.executeActions.js:37 (executeAction) ApiError: Light with id:10 was not found on this bridge
    at /home/vonox/repos/Gladys/server/services/philips-hue/node_modules/node-hue-api/lib/api/Lights.js:121:17
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async PhilipsHueLightHandler.setValue (/home/vonox/repos/Gladys/server/services/philips-hue/lib/light/light.setValue.js:38:3)

Like I said, restarting the app and the problem is gone.

For reference: https://github.com/GladysAssistant/Gladys/blob/master/server/services/philips-hue/lib/light/light.setValue.js

I've no clue about that, what do you think ?
Thank you

@peter-murray
Copy link
Owner

This might be due to the light state not being present in the bridge cache... I cannot remember if this is still used in that version (as I have been migrating the code base to TypeScript).

If a restart is clearing this out, that would be where I think the problem may be. I would need to set up a test scenario for that as I do not have an easy way to write an automation test for this.

@peter-murray
Copy link
Owner

Yeah, it is the guard that is in place on the cache...

return this.hueApi.getLightDefinition(lightId)

It will need to be refreshed and is currently done on start up when you connect for the first time, but I thought I might have included some update hooks around this. Clearly if these are being used I have missed your scenario.

How is the light being added? Is it done via this library? If so what which API calls are you making?

@VonOx
Copy link
Author

VonOx commented Jun 21, 2021

Hi Peter, sorry for delay

Light is paired with official Philips Hue application then listed via this library, unfortunately the light can't be controlled.

Thank you for feedback

@peter-murray
Copy link
Owner

Ok, so that explains it for me 🙇

The library only refreshes the cache on initial connection, or any activity that it performs with respect to pairing a new light (at least it should do as there is code to support the calling of the refresh code).

This means that if an external tool/system like the hue application is used to add a new light, the library needs to be prompted to update the cache of the lights that it retrieves upon first connection to the bridge (which is what it does when connecting for the first time).

You mention you were using 4.x version, so this call on the Api; https://github.com/peter-murray/node-hue-api/blob/4.x/lib/api/Api.js#L154 will re-sync with the bridge and pick up any new lights that were added between starting your application and then. The timestamp available from this function; https://github.com/peter-murray/node-hue-api/blob/4.x/lib/api/Api.js#L147 will indicate the last time that the api successfully performed a sync with the bridge.

This is a heavy weight call, and will not be needed unless there is external activities that are modifying the lights outside of the library.

@peter-murray
Copy link
Owner

@VonOx does the above details ☝️ explain why this is happening for you and match your use case? Can you issue the resync call via your integration when you need to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants