Restore_state helper to restore entity states from the DB on startup (#4614)

* Restore states

* feedback

* Remove component move into recorder

* space

* helper

* Address my own comments

* Improve test coverage

* Add test for light restore state
This commit is contained in:
Johann Kellerman authored and Paulus Schoutsen committed 2017-02-20 23:40:27 -08:00
1 parent 2b9fb73032
commit fdc373f27e
18 files changed
+425 -184

No files matched your search

@@ -15,6 +15,7 @@ from homeassistant.const import (
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import async_get_last_state
DOMAIN = 'input_boolean'
@@ -139,6 +140,14 @@ class InputBoolean(ToggleEntity):
"""Return true if entity is on."""
return self._state
@asyncio.coroutine
def async_added_to_hass(self):
"""Called when entity about to be added to hass."""
state = yield from async_get_last_state(self.hass, self.entity_id)
if not state:
return
self._state = state.state == 'on'
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""Turn the entity on."""