core/homeassistant/components/emulated_hue
Jean-Yves Avenard 988cbf12ce
Cache emulated hue states attributes between get and put calls to avoid unexpected alexa errors (#38451)
* Wait for the state of the entity to actually change before resolving PUT request

Additionally, we cache the entity's properties for up to two seconds for the successive GET state request

When Alexa issues a command to a Hue hub; it immediately queries the hub for the entity's state to confirm if the command was successful.
It expects the state to be effective immediately after the PUT request has been completed.
There may be a delay for the new state to actually be active, this is particularly obvious when using group lights.
This leads Alexa to report that the light had an error.

So we wait for the state of the entity to actually change before responding to the PUT request.

Due to rounding issue when converting the HA range (0..255) to Hue range (1..254) we now cache the state sets by Alexa and return those cached values for up to two seconds so that Alexa gets the same value as it originally set.

Fixes #38446

* Add new tests verifying emulated_hue behaviour.

* Increase code test coverage.

The remaining uncovered lines can't be tested as they mostly check that the hass framework or the http server properly work.

This commit doesn't attempt to fix exposed issues as it would be out of scope ; it merely create the tests to exercise the whole code.

* Update homeassistant/components/emulated_hue/hue_api.py

* Add test for state change wait timeout

* Preserve the cache long enough for groups to change

* Update tests/components/emulated_hue/test_hue_api.py

Co-authored-by: J. Nick Koston <nick@koston.org>
2020-08-03 15:30:16 -10:00
..
__init__.py Cache checking for entity exposure in emulated_hue (#37260) 2020-06-30 13:22:17 -05:00
const.py Fix emulated_hue compatibility with older devices (#36090) 2020-05-25 14:55:23 -05:00
hue_api.py Cache emulated hue states attributes between get and put calls to avoid unexpected alexa errors (#38451) 2020-08-03 15:30:16 -10:00
manifest.json Remove unused manifest fields (#33595) 2020-04-03 12:58:19 -07:00
services.yaml
upnp.py Avoid shutdown delays when emulated_hue is enabled (#38472) 2020-08-02 08:32:07 -10:00