mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Bugfix restore startup state (#6189)
This commit is contained in:
committed by
Paulus Schoutsen
parent
1d32bced1c
commit
c940d26f07
@@ -48,13 +48,15 @@ def _load_restore_cache(hass: HomeAssistant):
|
||||
@asyncio.coroutine
|
||||
def async_get_last_state(hass, entity_id: str):
|
||||
"""Helper to restore state."""
|
||||
if (_RECORDER not in hass.config.components or
|
||||
hass.state != CoreState.starting):
|
||||
return None
|
||||
|
||||
if DATA_RESTORE_CACHE in hass.data:
|
||||
return hass.data[DATA_RESTORE_CACHE].get(entity_id)
|
||||
|
||||
if (_RECORDER not in hass.config.components or
|
||||
hass.state not in (CoreState.starting, CoreState.not_running)):
|
||||
_LOGGER.error("Cache can only be loaded during startup, not %s",
|
||||
hass.state)
|
||||
return None
|
||||
|
||||
if _LOCK not in hass.data:
|
||||
hass.data[_LOCK] = asyncio.Lock(loop=hass.loop)
|
||||
|
||||
@@ -63,7 +65,7 @@ def async_get_last_state(hass, entity_id: str):
|
||||
yield from hass.loop.run_in_executor(
|
||||
None, _load_restore_cache, hass)
|
||||
|
||||
return hass.data[DATA_RESTORE_CACHE].get(entity_id)
|
||||
return hass.data.get(DATA_RESTORE_CACHE, {}).get(entity_id)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
Reference in New Issue
Block a user