Add support for JSON fragments (#107213)

This commit is contained in:
J. Nick Koston 2024-01-07 17:36:31 -10:00 committed by GitHub
parent 50edc334de
commit d04e2d56da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 289 additions and 103 deletions

View file

@ -31,6 +31,7 @@ from tests.common import (
MockModule,
MockPlatform,
async_fire_time_changed,
json_round_trip,
mock_integration,
mock_platform,
)
@ -318,12 +319,15 @@ async def test_dump_data(hass: HomeAssistant) -> None:
# b4 should not be written, since it is now expired
# 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"
state0 = json_round_trip(written_states[0])
state1 = json_round_trip(written_states[1])
state2 = json_round_trip(written_states[2])
assert state0["state"]["entity_id"] == "input_boolean.b1"
assert state0["state"]["state"] == "on"
assert state1["state"]["entity_id"] == "input_boolean.b3"
assert state1["state"]["state"] == "off"
assert state2["state"]["entity_id"] == "input_boolean.b5"
assert state2["state"]["state"] == "off"
# Test that removed entities are not persisted
await entity.async_remove()
@ -340,10 +344,12 @@ async def test_dump_data(hass: HomeAssistant) -> None:
args = mock_write_data.mock_calls[0][1]
written_states = args[0]
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"
state0 = json_round_trip(written_states[0])
state1 = json_round_trip(written_states[1])
assert state0["state"]["entity_id"] == "input_boolean.b3"
assert state0["state"]["state"] == "off"
assert state1["state"]["entity_id"] == "input_boolean.b5"
assert state1["state"]["state"] == "off"
async def test_dump_error(hass: HomeAssistant) -> None: