core/tests
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
..
auth Drop white blacklist pt1 (#37816) 2020-07-13 17:43:11 +02:00
components Cache emulated hue states attributes between get and put calls to avoid unexpected alexa errors (#38451) 2020-08-03 15:30:16 -10:00
fixtures Add basic websocket api for OZW (#38265) 2020-07-29 22:35:26 +02:00
hassfest
helpers Reduce time to reload yaml and check configuration (#38469) 2020-08-04 03:00:44 +02:00
mock Use asynctest-mock in most places (#35109) 2020-05-03 11:27:19 -07:00
resources
scripts Detect lingering threads after tests (#37270) 2020-07-09 16:15:14 +02:00
test_util Fix docstring in test_utils/aiohttp.py (#34040) 2020-04-11 20:20:19 +02:00
testing_config Address new issues flagged by flake8 3.8.0a2 (#34964) 2020-04-30 21:37:58 +02:00
util Round time values in get_age() to better approximate the actual age (#37125) 2020-07-09 11:19:38 -07:00
__init__.py
async_mock.py Use built-in test helpers on 3.8 (#34901) 2020-04-30 13:29:50 -07:00
bandit.yaml Enable some more bandit checks (#30857) 2020-01-20 18:44:55 +02:00
common.py Use event loop scheduling for tracking time patterns (#38021) 2020-07-20 20:18:31 -10:00
conftest.py Use event loop scheduling for tracking time patterns (#38021) 2020-07-20 20:18:31 -10:00
ignore_uncaught_exceptions.py Fix broken CI (#35314) 2020-05-06 18:40:21 -07:00
test_bootstrap.py Detect lingering threads after tests (#37270) 2020-07-09 16:15:14 +02:00
test_config.py Drop white blacklist pt1 (#37816) 2020-07-13 17:43:11 +02:00
test_config_entries.py ConfigFlow default discovery without unique ID (#36754) 2020-06-15 13:38:38 +02:00
test_core.py Fix flapping chained task logging test (#38492) 2020-08-03 15:01:15 +02:00
test_data_entry_flow.py Add current step that is in progress (#35272) 2020-05-05 21:34:51 -07:00
test_loader.py Improve after_dependencies handling (#36898) 2020-06-19 17:24:33 -07:00
test_main.py Use asynctest-mock in most places (#35109) 2020-05-03 11:27:19 -07:00
test_requirements.py Upgrade zeroconf to 0.27.1 (#36277) 2020-06-05 14:33:26 -07:00
test_setup.py Improve after_dependencies handling (#36898) 2020-06-19 17:24:33 -07:00