Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

def last_recorder_run():
"""Retireve the last closed recorder run from the DB."""
recorder.get_instance()
rec_runs = recorder.get_model('RecorderRuns')
with recorder.session_scope() as session:
res = recorder.query(rec_runs).order_by(rec_runs.end.desc()).first()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/input_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def async_added_to_hass(self):
state = yield from async_get_last_state(self.hass, self.entity_id)
if not state:
return
self._state = state.state == 'on'
self._state = state.state == STATE_ON

@asyncio.coroutine
def async_turn_on(self, **kwargs):
Expand Down
12 changes: 7 additions & 5 deletions homeassistant/helpers/restore_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ def remove_cache(event):
@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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have done this as we now will allow restoring from cache if we are running?

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)

Expand All @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this? There are no paths in _load_restore_cache that do not set the cache



@asyncio.coroutine
Expand Down