Bugfix restore startup state (#6189)
This commit is contained in:
parent
7fcc3ae00a
commit
477f621705
3 changed files with 9 additions and 6 deletions
|
@ -36,6 +36,7 @@ IGNORE_DOMAINS = ('zone', 'scene',)
|
||||||
|
|
||||||
def last_recorder_run():
|
def last_recorder_run():
|
||||||
"""Retireve the last closed recorder run from the DB."""
|
"""Retireve the last closed recorder run from the DB."""
|
||||||
|
recorder.get_instance()
|
||||||
rec_runs = recorder.get_model('RecorderRuns')
|
rec_runs = recorder.get_model('RecorderRuns')
|
||||||
with recorder.session_scope() as session:
|
with recorder.session_scope() as session:
|
||||||
res = recorder.query(rec_runs).order_by(rec_runs.end.desc()).first()
|
res = recorder.query(rec_runs).order_by(rec_runs.end.desc()).first()
|
||||||
|
|
|
@ -146,7 +146,7 @@ class InputBoolean(ToggleEntity):
|
||||||
state = yield from async_get_last_state(self.hass, self.entity_id)
|
state = yield from async_get_last_state(self.hass, self.entity_id)
|
||||||
if not state:
|
if not state:
|
||||||
return
|
return
|
||||||
self._state = state.state == 'on'
|
self._state = state.state == STATE_ON
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_turn_on(self, **kwargs):
|
def async_turn_on(self, **kwargs):
|
||||||
|
|
|
@ -48,13 +48,15 @@ def _load_restore_cache(hass: HomeAssistant):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_get_last_state(hass, entity_id: str):
|
def async_get_last_state(hass, entity_id: str):
|
||||||
"""Helper to restore state."""
|
"""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:
|
if DATA_RESTORE_CACHE in hass.data:
|
||||||
return hass.data[DATA_RESTORE_CACHE].get(entity_id)
|
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:
|
if _LOCK not in hass.data:
|
||||||
hass.data[_LOCK] = asyncio.Lock(loop=hass.loop)
|
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(
|
yield from hass.loop.run_in_executor(
|
||||||
None, _load_restore_cache, hass)
|
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
|
@asyncio.coroutine
|
||||||
|
|
Loading…
Add table
Reference in a new issue