Skip to content

Commit

Permalink
Restore states through a JSON store instead of recorder
Browse files Browse the repository at this point in the history
* Restore states through a JSON store

* Accept entity_id directly in restore state helper

* Keep states stored between runs for a limited time

* Remove warning
  • Loading branch information
claytonjn committed Dec 12, 2018
1 parent 9385c9f commit 19902f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions homeassistant/components/switch/circadian_lighting.py
Expand Up @@ -13,7 +13,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import dispatcher_connect
from homeassistant.helpers.event import track_state_change
from homeassistant.helpers.restore_state import async_get_last_state
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.components.light import (
is_on, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_RGB_COLOR, ATTR_TRANSITION,
ATTR_WHITE_VALUE, ATTR_XY_COLOR, DOMAIN as LIGHT_DOMAIN)
Expand Down Expand Up @@ -100,7 +100,7 @@ def update(call=None):
return False


class CircadianSwitch(SwitchDevice):
class CircadianSwitch(SwitchDevice, RestoreEntity):
"""Representation of a Circadian Lighting switch."""

def __init__(self, hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brightness,
Expand Down Expand Up @@ -166,10 +166,11 @@ def is_on(self):
async def async_added_to_hass(self):
"""Call when entity about to be added to hass."""
# If not None, we got an initial value.
await super().async_added_to_hass()
if self._state is not None:
return

state = await async_get_last_state(self.hass, self._entity_id)
state = await self.sync_get_last_state()
self._state = state and state.state == STATE_ON

@property
Expand Down

0 comments on commit 19902f6

Please sign in to comment.