Store state last seen time separately (#18806)

* Store state last seen time separately

This ensures that infrequently updated entities aren't accidentally
dropped from the restore states store

* Fix mock restore cache
This commit is contained in:
Adam Mills 2018-11-30 02:26:19 -05:00 committed by Paulus Schoutsen
parent a9dc4ba297
commit 22f27b8621
3 changed files with 80 additions and 44 deletions

View file

@ -715,9 +715,11 @@ def mock_restore_cache(hass, states):
"""Mock the DATA_RESTORE_CACHE."""
key = restore_state.DATA_RESTORE_STATE_TASK
data = restore_state.RestoreStateData(hass)
now = date_util.utcnow()
data.last_states = {
state.entity_id: state for state in states}
state.entity_id: restore_state.StoredState(state, now)
for state in states}
_LOGGER.debug('Restore cache: %s', data.last_states)
assert len(data.last_states) == len(states), \
"Duplicate entity_id? {}".format(states)