Pytest tests (#17750)
* Convert core tests
* Convert component tests to use pytest assert
* Lint 🤷♂️
* Fix test
* Fix 3 typos in docs
This commit is contained in:
parent
4222f7562b
commit
08fe7c3ece
223 changed files with 6747 additions and 7237 deletions
|
@ -75,17 +75,16 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
"""Test the flux switch when it is off."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=10, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -110,23 +109,22 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.hass, light.DOMAIN, SERVICE_TURN_ON)
|
||||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(turn_on_calls))
|
||||
assert 0 == len(turn_on_calls)
|
||||
|
||||
def test_flux_before_sunrise(self):
|
||||
"""Test the flux switch before sunrise."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=2, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -154,25 +152,24 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 112)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.606, 0.379])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_sunrise_before_sunset(self):
|
||||
"""Test the flux switch after sunrise and before sunset."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -201,25 +198,24 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 173)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.439, 0.37])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 173
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_sunset_before_stop(self):
|
||||
"""Test the flux switch after sunset and before stop."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -249,25 +245,24 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 146)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.506, 0.385])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 146
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_stop_before_sunrise(self):
|
||||
"""Test the flux switch after stop and before sunrise."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=23, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -295,25 +290,24 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 112)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.606, 0.379])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_with_custom_start_stop_times(self):
|
||||
"""Test the flux with custom start and stop times."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -344,8 +338,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 147)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.504, 0.385])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 147
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.504, 0.385]
|
||||
|
||||
def test_flux_before_sunrise_stop_next_day(self):
|
||||
"""Test the flux switch before sunrise.
|
||||
|
@ -354,17 +348,16 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
"""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=2, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -394,8 +387,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 112)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.606, 0.379])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_sunrise_before_sunset_stop_next_day(self):
|
||||
|
@ -406,17 +399,16 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
"""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -446,8 +438,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 173)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.439, 0.37])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 173
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_sunset_before_midnight_stop_next_day(self):
|
||||
|
@ -457,17 +449,16 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
"""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=23, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -496,8 +487,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 119)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.588, 0.386])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 119
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.588, 0.386]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_sunset_after_midnight_stop_next_day(self):
|
||||
|
@ -507,17 +498,16 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
"""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=00, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -547,8 +537,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 114)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.601, 0.382])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 114
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.601, 0.382]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_after_stop_before_sunrise_stop_next_day(self):
|
||||
|
@ -558,17 +548,16 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
"""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=2, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -598,25 +587,24 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 112)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.606, 0.379])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 112
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_with_custom_colortemps(self):
|
||||
"""Test the flux with custom start and stop colortemps."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -648,25 +636,24 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 159)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.469, 0.378])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 159
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.469, 0.378]
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_flux_with_custom_brightness(self):
|
||||
"""Test the flux with custom start and stop colortemps."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -697,16 +684,15 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 255)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.506, 0.385])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 255
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385]
|
||||
|
||||
def test_flux_with_multiple_lights(self):
|
||||
"""Test the flux switch with multiple light entities."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1, dev2, dev3 = platform.DEVICES
|
||||
common_light.turn_on(self.hass, entity_id=dev2.entity_id)
|
||||
|
@ -715,19 +701,19 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
state = self.hass.states.get(dev2.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
state = self.hass.states.get(dev3.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=12, minute=0, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -760,29 +746,28 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 163)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.46, 0.376])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 163
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
||||
call = turn_on_calls[-2]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 163)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.46, 0.376])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 163
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
||||
call = turn_on_calls[-3]
|
||||
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 163)
|
||||
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.46, 0.376])
|
||||
assert call.data[light.ATTR_BRIGHTNESS] == 163
|
||||
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
|
||||
|
||||
def test_flux_with_mired(self):
|
||||
"""Test the flux switch´s mode mired."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('color_temp') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -812,22 +797,21 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
fire_time_changed(self.hass, test_time)
|
||||
self.hass.block_till_done()
|
||||
call = turn_on_calls[-1]
|
||||
self.assertEqual(call.data[light.ATTR_COLOR_TEMP], 269)
|
||||
assert call.data[light.ATTR_COLOR_TEMP] == 269
|
||||
|
||||
def test_flux_with_rgb(self):
|
||||
"""Test the flux switch´s mode rgb."""
|
||||
platform = loader.get_component(self.hass, 'light.test')
|
||||
platform.init()
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
|
||||
assert setup_component(self.hass, light.DOMAIN,
|
||||
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
|
||||
|
||||
dev1 = platform.DEVICES[0]
|
||||
|
||||
# Verify initial state of light
|
||||
state = self.hass.states.get(dev1.entity_id)
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('color_temp') is None
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
|
@ -859,4 +843,4 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
call = turn_on_calls[-1]
|
||||
rgb = (255, 198, 152)
|
||||
rounded_call = tuple(map(round, call.data[light.ATTR_RGB_COLOR]))
|
||||
self.assertEqual(rounded_call, rgb)
|
||||
assert rounded_call == rgb
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue