* 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>
This issue has been corrected and then reverted multiple times.
It seems that the core issue was a casing one (On/off vs On/Off) ; for better
matching with a real Hue hub, also add the productname.
Tested to work with echo 2 and echo 5.
Since we now base all of exposure checks on data that
will not change, we can cache the result instead
of calculating it every loop.
This change complements the work done in #32718
* Make emulated hue detectable by Busch-Jaeger free@home SysAP
* Emulated hue: Remove unnecessary host line from UPnP response
* Test that external IPs are blocked for config route
* Add another test for unauthorized users
* Change hue username to nouser
nouser seems to be used by the official Hue Bridge v1 Android app and is
used by other projects as well
Co-authored-by: J. Nick Koston <nick@koston.org>
* Return emulated hue id for update requests
* Emulated Hue: Rename function argument to match its content
* Use HTTP status consts throughout the test
* Use HTTP status consts in UPnP test
* Fix emulated_hue brightness off by one
Hue uses a max brightness of 254, Home Assistant
uses a max brightness of 255. Values > 127 were
off by one.
* use constant
* fix test
* add debug
* Revert "add debug"
This reverts commit 242220a02e.
* emulated_hue: Optimize is_entity_exposed
Switch all list transversals in is_entity_exposed to
hash lookups
get_deprecated is now only called if explict_expose is
set
This funciton was iterating multiple lists per enitity
every time there was an update. It was responsible for
a chunk of execution time when there are large number
of entities in home assistant.
* Complete deprecation of ATTR_EMULATED_HUE attribute
* Complete deprecation of ATTR_EMULATED_HUE attribute (remove const)
* Remove ATTR_EMULATED_HUE_HIDDEN and Rewrite tests
* Fix light.turn_on for emulated_hue
HarmonyHub sends `{'xy': [0, 0], 'on': True, 'bri': 0}` when turning on lights that do not support brightness control. Unfortunately current logic always uses brightness value to control on/off state which makes no sense for lights that don't support brightness at all. This change fixes that behavior, making light without brightness control usable with HarmonyHub and probably some other remotes.
* Test 'no_brightness' lights
* Store last working HTTP settings
* Add safe mode
* Fix tests
* Add cloud to safe mode
* Update logging text
* Fix camera tests leaving files behind
* Make emulated_hue tests not leave files behind
* Make logbook tests not leave files behind
* Make tts tests not leave files behind
* Make image_processing tests not leave files behind
* Make manual_mqtt tests not leave files behind
If an entity is in unavailable state in HA, we expose this
as unreachable to Hue clients. This helps when troubleshooting
Hue issues because you can now receive feedback if there is an issue
on the HA side.
* Add bandit to pre-commit and CI, use to catch known vulnerable XML parsing
* Use defusedxml instead of direct xml.etree to parse XML
* Move config to tests/bandit.yaml
* [Hue API] Add color support
Adds color support to the hue api (specifically hue/saturation). Switched from using a tuple to convey state internally to using a dict to make adding new fields easier.
* [Hue API] Add unit test for color support
* set cover level using emulated_hue
* changed mapping for service turn_on/off for cover.
* removed whitespace for the sake of hound
* using const for domains instead of hardcoded strings.
* change length of lines for the sake of hound
* fixed under-intended line
* changed intent for the sake of hound
* Restore states through a JSON store
* Accept entity_id directly in restore state helper
* Keep states stored between runs for a limited time
* Remove warning
* Fixed file corruption bugs in private storage code.
* Restoring fixed test case.
* Implemented test suite for utils/json.py
* Added new unit test cases for util/json.py
* Dixed formatting nags
* Fixed more nags from the Hound
* Added doc strings to some very short functions
* Fixing lint's complains about my choice of parts of speach. Sigh.
* Moved atomic save operations down into util/json.py so that all benefit.
Added extra clean-up code to ensure that temporary files are removed in
case of errors.
Updated emulated_hue unit tests to avoid errors.
* Apparently 'e' is not allows as a variable name for an exception...
* Addded support for private storage.
Include 'private' flag parameters to the Store class and save_json function.
Updated various authentication and onboarding classes to use private stores.
Fixed unit test for emulated_hue which used a mock patch on save_json().
* Fixed Hound formatting issues not detected by local linting.