1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-27 14:31:13 +00:00

Fix state overwrite race condition where two platforms request the same entity_id (#42151)

* Fix state overwrite race condition where two platforms request the same entity id

* fix test

* create reservations instead

* revert

* cannot use __slots__ because we patch async_all
This commit is contained in:
J. Nick Koston
2020-10-21 10:01:51 -05:00
committed by GitHub
parent bb641c23a9
commit df2ede6522
7 changed files with 119 additions and 8 deletions

View File

@@ -1537,3 +1537,26 @@ async def test_hassjob_forbid_coroutine():
# To avoid warning about unawaited coro
await coro
async def test_reserving_states(hass):
"""Test we can reserve a state in the state machine."""
hass.states.async_reserve("light.bedroom")
assert hass.states.async_available("light.bedroom") is False
hass.states.async_set("light.bedroom", "on")
assert hass.states.async_available("light.bedroom") is False
with pytest.raises(ha.HomeAssistantError):
hass.states.async_reserve("light.bedroom")
hass.states.async_remove("light.bedroom")
assert hass.states.async_available("light.bedroom") is True
hass.states.async_set("light.bedroom", "on")
with pytest.raises(ha.HomeAssistantError):
hass.states.async_reserve("light.bedroom")
assert hass.states.async_available("light.bedroom") is False
hass.states.async_remove("light.bedroom")
assert hass.states.async_available("light.bedroom") is True