Correctly store removed entities for restore state (#25073)

* Correctly store removed entities for restore state

* Lint

* Do not assume about set encoding
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-07-10 20:41:03 -07:00
1 parent 312fceeaf6
commit 073327831f
2 files changed
+47 -5

No files matched your search

+14 -3
View File
@@ -1,6 +1,8 @@
"""The tests for the Restore component."""
from datetime import datetime
from asynctest import patch
from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.core import CoreState, State
from homeassistant.exceptions import HomeAssistantError
@@ -10,7 +12,6 @@ from homeassistant.helpers.restore_state import (
STORAGE_KEY)
from homeassistant.util import dt as dt_util
from asynctest import patch
from tests.common import mock_coro
@@ -208,7 +209,12 @@ async def test_state_saved_on_remove(hass):
entity.entity_id = 'input_boolean.b0'
await entity.async_internal_added_to_hass()
hass.states.async_set('input_boolean.b0', 'on')
now = dt_util.utcnow()
hass.states.async_set('input_boolean.b0', 'on', {
'complicated': {
'value': {1, 2, now}
}
})
data = await RestoreStateData.async_get_instance(hass)
@@ -218,7 +224,12 @@ async def test_state_saved_on_remove(hass):
await entity.async_remove()
# We should store the input boolean state when it is removed
assert data.last_states['input_boolean.b0'].state.state == 'on'
state = data.last_states['input_boolean.b0'].state
assert state.state == 'on'
assert isinstance(state.attributes['complicated']['value'], list)
assert set(state.attributes['complicated']['value']) == {
1, 2, now.isoformat()
}
async def test_restoring_invalid_entity_id(hass, hass_storage):