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
|
2016-09-21 04:26:40 +00:00
|
|
|
import unittest
|
|
|
|
|
2017-11-16 07:03:41 +00:00
|
|
|
from homeassistant.setup import setup_component
|
2016-09-21 04:26:40 +00:00
|
|
|
import homeassistant.components.light as light
|
|
|
|
|
2017-11-16 07:03:41 +00:00
|
|
|
from tests.common import get_test_home_assistant
|
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))
|
2017-05-18 02:20:59 +00:00
|
|
|
light.turn_on(self.hass, ENTITY_LIGHT, kelvin=3000, brightness_pct=50)
|
2017-05-17 06:00:46 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
state = self.hass.states.get(ENTITY_LIGHT)
|
2017-05-18 02:20:59 +00:00
|
|
|
self.assertEqual(333, state.attributes.get(light.ATTR_COLOR_TEMP))
|
2017-05-17 06:00:46 +00:00
|
|
|
self.assertEqual(127, state.attributes.get(light.ATTR_BRIGHTNESS))
|
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
|
|
|
|
2017-06-10 08:13:52 +00:00
|
|
|
def test_turn_off_without_entity_id(self):
|
|
|
|
"""Test light turn off all lights."""
|
|
|
|
light.turn_on(self.hass, ENTITY_LIGHT)
|
|
|
|
self.hass.block_till_done()
|
|
|
|
self.assertTrue(light.is_on(self.hass, ENTITY_LIGHT))
|
|
|
|
light.turn_off(self.hass)
|
|
|
|
self.hass.block_till_done()
|
|
|
|
self.assertFalse(light.is_on(self.hass, ENTITY_LIGHT))
|