2016-09-21 04:26:40 +00:00
|
|
|
"""The tests for the demo light component."""
|
2016-10-30 21:18:53 +00:00
|
|
|
# pylint: disable=protected-access
|
2017-02-21 07:40:27 +00:00
|
|
|
import asyncio
|
2016-09-21 04:26:40 +00:00
|
|
|
import unittest
|
|
|
|
|
2017-02-21 07:40:27 +00:00
|
|
|
from homeassistant.core import State, CoreState
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant.setup import setup_component, async_setup_component
|
2016-09-21 04:26:40 +00:00
|
|
|
import homeassistant.components.light as light
|
2017-02-21 07:40:27 +00:00
|
|
|
from homeassistant.helpers.restore_state import DATA_RESTORE_CACHE
|
2016-09-21 04:26:40 +00:00
|
|
|
|
2017-03-01 04:33:19 +00:00
|
|
|
from tests.common import get_test_home_assistant, mock_component
|
2016-09-21 04:26:40 +00:00
|
|
|
|
|
|
|
ENTITY_LIGHT = 'light.bed_light'
|
|
|
|
|
|
|
|
|
2017-02-21 07:40:27 +00:00
|
|
|
class TestDemoLight(unittest.TestCase):
|
|
|
|
"""Test the demo light."""
|
2016-09-21 04:26:40 +00:00
|
|
|
|
2016-10-30 21:18:53 +00:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def setUp(self):
|
2016-09-21 04:26:40 +00:00
|
|
|
"""Setup things to be run when tests are started."""
|
|
|
|
self.hass = get_test_home_assistant()
|
2016-09-25 21:15:21 +00:00
|
|
|
self.assertTrue(setup_component(self.hass, light.DOMAIN, {'light': {
|
2016-09-21 04:26:40 +00:00
|
|
|
'platform': 'demo',
|
|
|
|
}}))
|
|
|
|
|
2016-10-30 21:18:53 +00:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def tearDown(self):
|
2016-09-21 04:26:40 +00:00
|
|
|
"""Stop down everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_state_attributes(self):
|
|
|
|
"""Test light state attributes."""
|
|
|
|
light.turn_on(
|
|
|
|
self.hass, ENTITY_LIGHT, xy_color=(.4, .6), brightness=25)
|
2016-10-31 15:47:29 +00:00
|
|
|
self.hass.block_till_done()
|
2016-09-21 04:26:40 +00:00
|
|
|
state = self.hass.states.get(ENTITY_LIGHT)
|
|
|
|
self.assertTrue(light.is_on(self.hass, ENTITY_LIGHT))
|
|
|
|
self.assertEqual((.4, .6), state.attributes.get(light.ATTR_XY_COLOR))
|
|
|
|
self.assertEqual(25, state.attributes.get(light.ATTR_BRIGHTNESS))
|
|
|
|
self.assertEqual(
|
2017-03-02 07:54:45 +00:00
|
|
|
(76, 95, 0), state.attributes.get(light.ATTR_RGB_COLOR))
|
2016-11-28 01:15:28 +00:00
|
|
|
self.assertEqual('rainbow', state.attributes.get(light.ATTR_EFFECT))
|
2016-09-21 04:26:40 +00:00
|
|
|
light.turn_on(
|
|
|
|
self.hass, ENTITY_LIGHT, rgb_color=(251, 252, 253),
|
|
|
|
white_value=254)
|
2016-10-31 15:47:29 +00:00
|
|
|
self.hass.block_till_done()
|
2016-09-21 04:26:40 +00:00
|
|
|
state = self.hass.states.get(ENTITY_LIGHT)
|
|
|
|
self.assertEqual(254, state.attributes.get(light.ATTR_WHITE_VALUE))
|
|
|
|
self.assertEqual(
|
|
|
|
(251, 252, 253), state.attributes.get(light.ATTR_RGB_COLOR))
|
2016-11-28 01:15:28 +00:00
|
|
|
light.turn_on(self.hass, ENTITY_LIGHT, color_temp=400, effect='none')
|
2016-10-31 15:47:29 +00:00
|
|
|
self.hass.block_till_done()
|
2016-09-21 04:26:40 +00:00
|
|
|
state = self.hass.states.get(ENTITY_LIGHT)
|
|
|
|
self.assertEqual(400, state.attributes.get(light.ATTR_COLOR_TEMP))
|
2017-04-29 22:04:20 +00:00
|
|
|
self.assertEqual(154, state.attributes.get(light.ATTR_MIN_MIREDS))
|
|
|
|
self.assertEqual(500, state.attributes.get(light.ATTR_MAX_MIREDS))
|
2016-11-28 01:15:28 +00:00
|
|
|
self.assertEqual('none', state.attributes.get(light.ATTR_EFFECT))
|
2016-09-21 04:26:40 +00:00
|
|
|
|
|
|
|
def test_turn_off(self):
|
|
|
|
"""Test light turn off method."""
|
|
|
|
light.turn_on(self.hass, ENTITY_LIGHT)
|
2016-10-31 15:47:29 +00:00
|
|
|
self.hass.block_till_done()
|
2016-09-21 04:26:40 +00:00
|
|
|
self.assertTrue(light.is_on(self.hass, ENTITY_LIGHT))
|
|
|
|
light.turn_off(self.hass, ENTITY_LIGHT)
|
2016-10-31 15:47:29 +00:00
|
|
|
self.hass.block_till_done()
|
2016-09-21 04:26:40 +00:00
|
|
|
self.assertFalse(light.is_on(self.hass, ENTITY_LIGHT))
|
2017-02-21 07:40:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_restore_state(hass):
|
|
|
|
"""Test state gets restored."""
|
2017-03-01 04:33:19 +00:00
|
|
|
mock_component(hass, 'recorder')
|
2017-02-21 07:40:27 +00:00
|
|
|
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'
|