1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 05:57:01 +00:00

Restore state helper to work with entity registry restoration (#30451)

* Restore state helper to work with entity registry restoratino

* Update restore_state.py
This commit is contained in:
Paulus Schoutsen
2020-01-05 11:58:59 +01:00
committed by GitHub
parent 2ac5862eda
commit 24b25b8917
2 changed files with 21 additions and 5 deletions

View File

@@ -103,6 +103,7 @@ async def test_dump_data(hass):
State("input_boolean.b0", "on"),
State("input_boolean.b1", "on"),
State("input_boolean.b2", "on"),
State("input_boolean.b5", "unavailable", {"restored": True}),
]
entity = Entity()
@@ -126,6 +127,7 @@ async def test_dump_data(hass):
State("input_boolean.b4", "off"),
datetime(1985, 10, 26, 1, 22, tzinfo=dt_util.UTC),
),
"input_boolean.b5": StoredState(State("input_boolean.b5", "off"), now),
}
with patch(
@@ -142,11 +144,14 @@ async def test_dump_data(hass):
# b2 should not be written, since it is not registered with the helper
# b3 should be written, since it is still not expired
# b4 should not be written, since it is now expired
assert len(written_states) == 2
# b5 should be written, since current state is restored by entity registry
assert len(written_states) == 3
assert written_states[0]["state"]["entity_id"] == "input_boolean.b1"
assert written_states[0]["state"]["state"] == "on"
assert written_states[1]["state"]["entity_id"] == "input_boolean.b3"
assert written_states[1]["state"]["state"] == "off"
assert written_states[2]["state"]["entity_id"] == "input_boolean.b5"
assert written_states[2]["state"]["state"] == "off"
# Test that removed entities are not persisted
await entity.async_remove()
@@ -159,9 +164,11 @@ async def test_dump_data(hass):
assert mock_write_data.called
args = mock_write_data.mock_calls[0][1]
written_states = args[0]
assert len(written_states) == 1
assert len(written_states) == 2
assert written_states[0]["state"]["entity_id"] == "input_boolean.b3"
assert written_states[0]["state"]["state"] == "off"
assert written_states[1]["state"]["entity_id"] == "input_boolean.b5"
assert written_states[1]["state"]["state"] == "off"
async def test_dump_error(hass):