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:
parent
2b9fb73032
commit
fdc373f27e
18 changed files with 425 additions and 184 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue