Cleanup old stale restore feature (#10593)
* Cleanup old stale restore feature * cleanup * Update __init__.py * Update test_demo.py * Lintpull/8769/merge
parent
d4bd4c114b
commit
1719fa7008
|
@ -23,7 +23,6 @@ from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.restore_state import async_restore_state
|
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
DOMAIN = "light"
|
DOMAIN = "light"
|
||||||
|
@ -140,14 +139,6 @@ PROFILE_SCHEMA = vol.Schema(
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def extract_info(state):
|
|
||||||
"""Extract light parameters from a state object."""
|
|
||||||
params = {key: state.attributes[key] for key in PROP_TO_ATTR
|
|
||||||
if key in state.attributes}
|
|
||||||
params['is_on'] = state.state == STATE_ON
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def is_on(hass, entity_id=None):
|
def is_on(hass, entity_id=None):
|
||||||
"""Return if the lights are on based on the statemachine."""
|
"""Return if the lights are on based on the statemachine."""
|
||||||
|
@ -431,9 +422,3 @@ class Light(ToggleEntity):
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def async_added_to_hass(self):
|
|
||||||
"""Component added, restore_state using platforms."""
|
|
||||||
if hasattr(self, 'async_restore_state'):
|
|
||||||
yield from async_restore_state(self, extract_info)
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ Demo light platform that implements lights.
|
||||||
For more details about this platform, please refer to the documentation
|
For more details about this platform, please refer to the documentation
|
||||||
https://home-assistant.io/components/demo/
|
https://home-assistant.io/components/demo/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
|
@ -150,26 +149,3 @@ class DemoLight(Light):
|
||||||
# As we have disabled polling, we need to inform
|
# As we have disabled polling, we need to inform
|
||||||
# Home Assistant about updates in our state ourselves.
|
# Home Assistant about updates in our state ourselves.
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def async_restore_state(self, is_on, **kwargs):
|
|
||||||
"""Restore the demo state."""
|
|
||||||
self._state = is_on
|
|
||||||
|
|
||||||
if 'brightness' in kwargs:
|
|
||||||
self._brightness = kwargs['brightness']
|
|
||||||
|
|
||||||
if 'color_temp' in kwargs:
|
|
||||||
self._ct = kwargs['color_temp']
|
|
||||||
|
|
||||||
if 'rgb_color' in kwargs:
|
|
||||||
self._rgb = kwargs['rgb_color']
|
|
||||||
|
|
||||||
if 'xy_color' in kwargs:
|
|
||||||
self._xy_color = kwargs['xy_color']
|
|
||||||
|
|
||||||
if 'white_value' in kwargs:
|
|
||||||
self._white = kwargs['white_value']
|
|
||||||
|
|
||||||
if 'effect' in kwargs:
|
|
||||||
self._effect = kwargs['effect']
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
"""The tests for the demo light component."""
|
"""The tests for the demo light component."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import asyncio
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from homeassistant.core import State, CoreState
|
from homeassistant.setup import setup_component
|
||||||
from homeassistant.setup import setup_component, async_setup_component
|
|
||||||
import homeassistant.components.light as light
|
import homeassistant.components.light as light
|
||||||
from homeassistant.helpers.restore_state import DATA_RESTORE_CACHE
|
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant, mock_component
|
from tests.common import get_test_home_assistant
|
||||||
|
|
||||||
ENTITY_LIGHT = 'light.bed_light'
|
ENTITY_LIGHT = 'light.bed_light'
|
||||||
|
|
||||||
|
@ -79,36 +76,3 @@ class TestDemoLight(unittest.TestCase):
|
||||||
light.turn_off(self.hass)
|
light.turn_off(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertFalse(light.is_on(self.hass, ENTITY_LIGHT))
|
self.assertFalse(light.is_on(self.hass, ENTITY_LIGHT))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_restore_state(hass):
|
|
||||||
"""Test state gets restored."""
|
|
||||||
mock_component(hass, 'recorder')
|
|
||||||
hass.state = CoreState.starting
|
|
||||||
hass.data[DATA_RESTORE_CACHE] = {
|
|
||||||
'light.bed_light': State('light.bed_light', 'on', {
|
|
||||||
'brightness': 'value-brightness',
|
|
||||||
'color_temp': 'value-color_temp',
|
|
||||||
'rgb_color': 'value-rgb_color',
|
|
||||||
'xy_color': 'value-xy_color',
|
|
||||||
'white_value': 'value-white_value',
|
|
||||||
'effect': 'value-effect',
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
yield from async_setup_component(hass, 'light', {
|
|
||||||
'light': {
|
|
||||||
'platform': 'demo',
|
|
||||||
}})
|
|
||||||
|
|
||||||
state = hass.states.get('light.bed_light')
|
|
||||||
assert state is not None
|
|
||||||
assert state.entity_id == 'light.bed_light'
|
|
||||||
assert state.state == 'on'
|
|
||||||
assert state.attributes.get('brightness') == 'value-brightness'
|
|
||||||
assert state.attributes.get('color_temp') == 'value-color_temp'
|
|
||||||
assert state.attributes.get('rgb_color') == 'value-rgb_color'
|
|
||||||
assert state.attributes.get('xy_color') == 'value-xy_color'
|
|
||||||
assert state.attributes.get('white_value') == 'value-white_value'
|
|
||||||
assert state.attributes.get('effect') == 'value-effect'
|
|
||||||
|
|
Loading…
Reference in New Issue