mirror of
https://github.com/home-assistant/core.git
synced 2026-05-04 20:04:35 +02:00
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:
@@ -33,29 +33,29 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
'command_on': 'echo 1 > {}'.format(path),
|
||||
'command_off': 'echo 0 > {}'.format(path),
|
||||
}
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'command_line',
|
||||
'switches': {
|
||||
'test': test_switch
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
common.turn_on(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
def test_state_value(self):
|
||||
"""Test with state value."""
|
||||
@@ -67,29 +67,29 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
'command_off': 'echo 0 > {}'.format(path),
|
||||
'value_template': '{{ value=="1" }}'
|
||||
}
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'command_line',
|
||||
'switches': {
|
||||
'test': test_switch
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
common.turn_on(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
def test_state_json_value(self):
|
||||
"""Test with state JSON value."""
|
||||
@@ -103,29 +103,29 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
'command_off': 'echo \'{}\' > {}'.format(offcmd, path),
|
||||
'value_template': '{{ value_json.status=="ok" }}'
|
||||
}
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'command_line',
|
||||
'switches': {
|
||||
'test': test_switch
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
common.turn_on(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
def test_state_code(self):
|
||||
"""Test with state code."""
|
||||
@@ -136,29 +136,29 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
'command_on': 'echo 1 > {}'.format(path),
|
||||
'command_off': 'echo 0 > {}'.format(path),
|
||||
}
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'command_line',
|
||||
'switches': {
|
||||
'test': test_switch
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
common.turn_on(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
def test_assumed_state_should_be_true_if_command_state_is_none(self):
|
||||
"""Test with state value."""
|
||||
@@ -175,13 +175,13 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
]
|
||||
|
||||
no_state_device = command_line.CommandSwitch(*init_args)
|
||||
self.assertTrue(no_state_device.assumed_state)
|
||||
assert no_state_device.assumed_state
|
||||
|
||||
# Set state command
|
||||
init_args[-2] = 'cat {}'
|
||||
|
||||
state_device = command_line.CommandSwitch(*init_args)
|
||||
self.assertFalse(state_device.assumed_state)
|
||||
assert not state_device.assumed_state
|
||||
|
||||
def test_entity_id_set_correctly(self):
|
||||
"""Test that entity_id is set correctly from object_id."""
|
||||
@@ -196,5 +196,5 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
]
|
||||
|
||||
test_switch = command_line.CommandSwitch(*init_args)
|
||||
self.assertEqual(test_switch.entity_id, 'switch.test_device_name')
|
||||
self.assertEqual(test_switch.name, 'Test friendly name!')
|
||||
assert test_switch.entity_id == 'switch.test_device_name'
|
||||
assert test_switch.name == 'Test friendly name!'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -31,51 +31,48 @@ class TestSwitch(unittest.TestCase):
|
||||
|
||||
def test_methods(self):
|
||||
"""Test is_on, turn_on, turn_off methods."""
|
||||
self.assertTrue(setup_component(
|
||||
assert setup_component(
|
||||
self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}}
|
||||
))
|
||||
self.assertTrue(switch.is_on(self.hass))
|
||||
self.assertEqual(
|
||||
STATE_ON,
|
||||
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
|
||||
self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id))
|
||||
self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id))
|
||||
self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id))
|
||||
)
|
||||
assert switch.is_on(self.hass)
|
||||
assert STATE_ON == \
|
||||
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
|
||||
assert switch.is_on(self.hass, self.switch_1.entity_id)
|
||||
assert not switch.is_on(self.hass, self.switch_2.entity_id)
|
||||
assert not switch.is_on(self.hass, self.switch_3.entity_id)
|
||||
|
||||
common.turn_off(self.hass, self.switch_1.entity_id)
|
||||
common.turn_on(self.hass, self.switch_2.entity_id)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(switch.is_on(self.hass))
|
||||
self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id))
|
||||
self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id))
|
||||
assert switch.is_on(self.hass)
|
||||
assert not switch.is_on(self.hass, self.switch_1.entity_id)
|
||||
assert switch.is_on(self.hass, self.switch_2.entity_id)
|
||||
|
||||
# Turn all off
|
||||
common.turn_off(self.hass)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(switch.is_on(self.hass))
|
||||
self.assertEqual(
|
||||
STATE_OFF,
|
||||
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
|
||||
self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id))
|
||||
self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id))
|
||||
self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id))
|
||||
assert not switch.is_on(self.hass)
|
||||
assert STATE_OFF == \
|
||||
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
|
||||
assert not switch.is_on(self.hass, self.switch_1.entity_id)
|
||||
assert not switch.is_on(self.hass, self.switch_2.entity_id)
|
||||
assert not switch.is_on(self.hass, self.switch_3.entity_id)
|
||||
|
||||
# Turn all on
|
||||
common.turn_on(self.hass)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(switch.is_on(self.hass))
|
||||
self.assertEqual(
|
||||
STATE_ON,
|
||||
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
|
||||
self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id))
|
||||
self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id))
|
||||
self.assertTrue(switch.is_on(self.hass, self.switch_3.entity_id))
|
||||
assert switch.is_on(self.hass)
|
||||
assert STATE_ON == \
|
||||
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
|
||||
assert switch.is_on(self.hass, self.switch_1.entity_id)
|
||||
assert switch.is_on(self.hass, self.switch_2.entity_id)
|
||||
assert switch.is_on(self.hass, self.switch_3.entity_id)
|
||||
|
||||
def test_setup_two_platforms(self):
|
||||
"""Test with bad configuration."""
|
||||
@@ -86,12 +83,12 @@ class TestSwitch(unittest.TestCase):
|
||||
loader.set_component(self.hass, 'switch.test2', test_platform)
|
||||
test_platform.init(False)
|
||||
|
||||
self.assertTrue(setup_component(
|
||||
assert setup_component(
|
||||
self.hass, switch.DOMAIN, {
|
||||
switch.DOMAIN: {CONF_PLATFORM: 'test'},
|
||||
'{} 2'.format(switch.DOMAIN): {CONF_PLATFORM: 'test2'},
|
||||
}
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
async def test_switch_context(hass):
|
||||
|
||||
@@ -60,13 +60,13 @@ class TestMfiSwitch(unittest.TestCase):
|
||||
|
||||
def test_name(self):
|
||||
"""Test the name."""
|
||||
self.assertEqual(self.port.label, self.switch.name)
|
||||
assert self.port.label == self.switch.name
|
||||
|
||||
def test_update(self):
|
||||
"""Test update."""
|
||||
self.switch.update()
|
||||
self.assertEqual(self.port.refresh.call_count, 1)
|
||||
self.assertEqual(self.port.refresh.call_args, mock.call())
|
||||
assert self.port.refresh.call_count == 1
|
||||
assert self.port.refresh.call_args == mock.call()
|
||||
|
||||
def test_update_with_target_state(self):
|
||||
"""Test update with target state."""
|
||||
@@ -74,39 +74,39 @@ class TestMfiSwitch(unittest.TestCase):
|
||||
self.port.data = {}
|
||||
self.port.data['output'] = 'stale'
|
||||
self.switch.update()
|
||||
self.assertEqual(1.0, self.port.data['output'])
|
||||
self.assertEqual(None, self.switch._target_state)
|
||||
assert 1.0 == self.port.data['output']
|
||||
assert self.switch._target_state is None
|
||||
self.port.data['output'] = 'untouched'
|
||||
self.switch.update()
|
||||
self.assertEqual('untouched', self.port.data['output'])
|
||||
assert 'untouched' == self.port.data['output']
|
||||
|
||||
def test_turn_on(self):
|
||||
"""Test turn_on."""
|
||||
self.switch.turn_on()
|
||||
self.assertEqual(self.port.control.call_count, 1)
|
||||
self.assertEqual(self.port.control.call_args, mock.call(True))
|
||||
self.assertTrue(self.switch._target_state)
|
||||
assert self.port.control.call_count == 1
|
||||
assert self.port.control.call_args == mock.call(True)
|
||||
assert self.switch._target_state
|
||||
|
||||
def test_turn_off(self):
|
||||
"""Test turn_off."""
|
||||
self.switch.turn_off()
|
||||
self.assertEqual(self.port.control.call_count, 1)
|
||||
self.assertEqual(self.port.control.call_args, mock.call(False))
|
||||
self.assertFalse(self.switch._target_state)
|
||||
assert self.port.control.call_count == 1
|
||||
assert self.port.control.call_args == mock.call(False)
|
||||
assert not self.switch._target_state
|
||||
|
||||
def test_current_power_w(self):
|
||||
"""Test current power."""
|
||||
self.port.data = {'active_pwr': 10}
|
||||
self.assertEqual(10, self.switch.current_power_w)
|
||||
assert 10 == self.switch.current_power_w
|
||||
|
||||
def test_current_power_w_no_data(self):
|
||||
"""Test current power if there is no data."""
|
||||
self.port.data = {'notpower': 123}
|
||||
self.assertEqual(0, self.switch.current_power_w)
|
||||
assert 0 == self.switch.current_power_w
|
||||
|
||||
def test_device_state_attributes(self):
|
||||
"""Test the state attributes."""
|
||||
self.port.data = {'v_rms': 1.25,
|
||||
'i_rms': 2.75}
|
||||
self.assertEqual({'volts': 1.2, 'amps': 2.8},
|
||||
self.switch.device_state_attributes)
|
||||
assert {'volts': 1.2, 'amps': 2.8} == \
|
||||
self.switch.device_state_attributes
|
||||
|
||||
@@ -51,7 +51,7 @@ class TestMochadSwitchSetup(unittest.TestCase):
|
||||
],
|
||||
}
|
||||
}
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, good_config))
|
||||
assert setup_component(self.hass, switch.DOMAIN, good_config)
|
||||
|
||||
|
||||
class TestMochadSwitch(unittest.TestCase):
|
||||
@@ -71,7 +71,7 @@ class TestMochadSwitch(unittest.TestCase):
|
||||
|
||||
def test_name(self):
|
||||
"""Test the name."""
|
||||
self.assertEqual('fake_switch', self.switch.name)
|
||||
assert 'fake_switch' == self.switch.name
|
||||
|
||||
def test_turn_on(self):
|
||||
"""Test turn_on."""
|
||||
|
||||
@@ -42,20 +42,20 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
def test_sending_mqtt_commands_and_optimistic(self):
|
||||
"""Test the sending MQTT commands in optimistic mode."""
|
||||
@@ -75,8 +75,8 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.turn_on(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
@@ -85,7 +85,7 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
'command-topic', 'beer on', 2, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'switch.test')
|
||||
self.hass.block_till_done()
|
||||
@@ -93,7 +93,7 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'command-topic', 'beer off', 2, False)
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
def test_controlling_state_via_topic_and_json_message(self):
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
@@ -110,19 +110,19 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer on"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer off"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
def test_controlling_availability(self):
|
||||
"""Test the controlling state via topic."""
|
||||
@@ -141,32 +141,32 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', '0')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
def test_default_availability_payload(self):
|
||||
"""Test the availability payload."""
|
||||
@@ -183,32 +183,32 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', 'online')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', 'offline')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', 'online')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
def test_custom_availability_payload(self):
|
||||
"""Test the availability payload."""
|
||||
@@ -227,32 +227,32 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', 'good')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', 'nogood')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability_topic', 'good')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
def test_custom_state_payload(self):
|
||||
"""Test the state payload."""
|
||||
@@ -270,20 +270,20 @@ class TestSwitchMQTT(unittest.TestCase):
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', 'HIGH')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', 'LOW')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
|
||||
async def test_unique_id(hass):
|
||||
|
||||
@@ -28,29 +28,29 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
|
||||
def test_valid_config(self):
|
||||
"""Test configuration."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'0b1100cd0213c7f210010f51': {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
}}})
|
||||
|
||||
def test_valid_config_int_device_id(self):
|
||||
"""Test configuration."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{710000141010170: {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
}}})
|
||||
|
||||
def test_invalid_config1(self):
|
||||
"""Test invalid configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
assert not setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
@@ -58,11 +58,11 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51',
|
||||
'signal_repetitions': 3}
|
||||
}}}))
|
||||
}}})
|
||||
|
||||
def test_invalid_config2(self):
|
||||
"""Test invalid configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
assert not setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'invalid_key': 'afda',
|
||||
@@ -71,11 +71,11 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
}}})
|
||||
|
||||
def test_invalid_config3(self):
|
||||
"""Test invalid configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
assert not setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
@@ -83,96 +83,96 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
'name': 'Test',
|
||||
'packetid': 'AA1100cd0213c7f210010f51',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
}}})
|
||||
|
||||
def test_invalid_config4(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
assert not setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
}}})
|
||||
|
||||
def test_default_config(self):
|
||||
"""Test with 0 switches."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'devices':
|
||||
{}}}))
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
{}}})
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
def test_old_config(self):
|
||||
"""Test with 1 switch."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'devices':
|
||||
{'123efab1': {
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51'}}}}))
|
||||
'packetid': '0b1100cd0213c7f210010f51'}}}})
|
||||
|
||||
import RFXtrx as rfxtrxmod
|
||||
rfxtrx_core.RFXOBJECT =\
|
||||
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
||||
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||
entity = rfxtrx_core.RFX_DEVICES['213c7f216']
|
||||
self.assertEqual('Test', entity.name)
|
||||
self.assertEqual('off', entity.state)
|
||||
self.assertTrue(entity.assumed_state)
|
||||
self.assertEqual(entity.signal_repetitions, 1)
|
||||
self.assertFalse(entity.should_fire_event)
|
||||
self.assertFalse(entity.should_poll)
|
||||
assert 'Test' == entity.name
|
||||
assert 'off' == entity.state
|
||||
assert entity.assumed_state
|
||||
assert entity.signal_repetitions == 1
|
||||
assert not entity.should_fire_event
|
||||
assert not entity.should_poll
|
||||
|
||||
self.assertFalse(entity.is_on)
|
||||
assert not entity.is_on
|
||||
entity.turn_on()
|
||||
self.assertTrue(entity.is_on)
|
||||
assert entity.is_on
|
||||
entity.turn_off()
|
||||
self.assertFalse(entity.is_on)
|
||||
assert not entity.is_on
|
||||
|
||||
def test_one_switch(self):
|
||||
"""Test with 1 switch."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'devices':
|
||||
{'0b1100cd0213c7f210010f51': {
|
||||
'name': 'Test'}}}}))
|
||||
'name': 'Test'}}}})
|
||||
|
||||
import RFXtrx as rfxtrxmod
|
||||
rfxtrx_core.RFXOBJECT =\
|
||||
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
||||
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||
entity = rfxtrx_core.RFX_DEVICES['213c7f216']
|
||||
self.assertEqual('Test', entity.name)
|
||||
self.assertEqual('off', entity.state)
|
||||
self.assertTrue(entity.assumed_state)
|
||||
self.assertEqual(entity.signal_repetitions, 1)
|
||||
self.assertFalse(entity.should_fire_event)
|
||||
self.assertFalse(entity.should_poll)
|
||||
assert 'Test' == entity.name
|
||||
assert 'off' == entity.state
|
||||
assert entity.assumed_state
|
||||
assert entity.signal_repetitions == 1
|
||||
assert not entity.should_fire_event
|
||||
assert not entity.should_poll
|
||||
|
||||
self.assertFalse(entity.is_on)
|
||||
assert not entity.is_on
|
||||
entity.turn_on()
|
||||
self.assertTrue(entity.is_on)
|
||||
assert entity.is_on
|
||||
entity.turn_off()
|
||||
self.assertFalse(entity.is_on)
|
||||
assert not entity.is_on
|
||||
|
||||
entity_id = rfxtrx_core.RFX_DEVICES['213c7f216'].entity_id
|
||||
entity_hass = self.hass.states.get(entity_id)
|
||||
self.assertEqual('Test', entity_hass.name)
|
||||
self.assertEqual('off', entity_hass.state)
|
||||
assert 'Test' == entity_hass.name
|
||||
assert 'off' == entity_hass.state
|
||||
entity.turn_on()
|
||||
entity_hass = self.hass.states.get(entity_id)
|
||||
self.assertEqual('on', entity_hass.state)
|
||||
assert 'on' == entity_hass.state
|
||||
entity.turn_off()
|
||||
entity_hass = self.hass.states.get(entity_id)
|
||||
self.assertEqual('off', entity_hass.state)
|
||||
assert 'off' == entity_hass.state
|
||||
|
||||
def test_several_switches(self):
|
||||
"""Test with 3 switches."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'signal_repetitions': 3,
|
||||
'devices':
|
||||
@@ -181,34 +181,34 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
'0b1100100118cdea02010f70': {
|
||||
'name': 'Bath'},
|
||||
'0b1100101118cdea02010f70': {
|
||||
'name': 'Living'}}}}))
|
||||
'name': 'Living'}}}})
|
||||
|
||||
self.assertEqual(3, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 3 == len(rfxtrx_core.RFX_DEVICES)
|
||||
device_num = 0
|
||||
for id in rfxtrx_core.RFX_DEVICES:
|
||||
entity = rfxtrx_core.RFX_DEVICES[id]
|
||||
self.assertEqual(entity.signal_repetitions, 3)
|
||||
assert entity.signal_repetitions == 3
|
||||
if entity.name == 'Living':
|
||||
device_num = device_num + 1
|
||||
self.assertEqual('off', entity.state)
|
||||
self.assertEqual('<Entity Living: off>', entity.__str__())
|
||||
assert 'off' == entity.state
|
||||
assert '<Entity Living: off>' == entity.__str__()
|
||||
elif entity.name == 'Bath':
|
||||
device_num = device_num + 1
|
||||
self.assertEqual('off', entity.state)
|
||||
self.assertEqual('<Entity Bath: off>', entity.__str__())
|
||||
assert 'off' == entity.state
|
||||
assert '<Entity Bath: off>' == entity.__str__()
|
||||
elif entity.name == 'Test':
|
||||
device_num = device_num + 1
|
||||
self.assertEqual('off', entity.state)
|
||||
self.assertEqual('<Entity Test: off>', entity.__str__())
|
||||
assert 'off' == entity.state
|
||||
assert '<Entity Test: off>' == entity.__str__()
|
||||
|
||||
self.assertEqual(3, device_num)
|
||||
assert 3 == device_num
|
||||
|
||||
def test_discover_switch(self):
|
||||
"""Test with discovery of switches."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices': {}}}))
|
||||
'devices': {}}})
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x10, 0x01, 0x18,
|
||||
@@ -216,12 +216,12 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
entity = rfxtrx_core.RFX_DEVICES['118cdea2']
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual('<Entity 0b1100100118cdea01010f70: on>',
|
||||
entity.__str__())
|
||||
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||
assert '<Entity 0b1100100118cdea01010f70: on>' == \
|
||||
entity.__str__()
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdeb02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
||||
@@ -229,70 +229,70 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
entity = rfxtrx_core.RFX_DEVICES['118cdeb2']
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual('<Entity 0b1100120118cdea02000070: on>',
|
||||
entity.__str__())
|
||||
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||
assert '<Entity 0b1100120118cdea02000070: on>' == \
|
||||
entity.__str__()
|
||||
|
||||
# Trying to add a sensor
|
||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
# Trying to add a light
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x11, 0x10, 0x01, 0x18,
|
||||
0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
# Trying to add a rollershutter
|
||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
def test_discover_switch_noautoadd(self):
|
||||
"""Test with discovery of switch when auto add is False."""
|
||||
self.assertTrue(setup_component(self.hass, 'switch', {
|
||||
assert setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': False,
|
||||
'devices': {}}}))
|
||||
'devices': {}}})
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x10, 0x01, 0x18,
|
||||
0xcd, 0xea, 0x01, 0x01, 0x0f, 0x70])
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdeb02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x00, 0x12, 0x01, 0x18,
|
||||
0xcd, 0xea, 0x02, 0x00, 0x00, 0x70])
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
# Trying to add a sensor
|
||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
# Trying to add a light
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x11, 0x10, 0x01,
|
||||
0x18, 0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
# Trying to add a rollershutter
|
||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
||||
|
||||
@@ -74,59 +74,59 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
||||
self.add_entities,
|
||||
None)
|
||||
|
||||
self.assertEqual(len(self.DEVICES), 3)
|
||||
assert len(self.DEVICES) == 3
|
||||
|
||||
tested = 0
|
||||
|
||||
for device in self.DEVICES:
|
||||
if device.subscription == '555555':
|
||||
self.assertEqual('Vultr {}', device.name)
|
||||
assert 'Vultr {}' == device.name
|
||||
tested += 1
|
||||
|
||||
device.update()
|
||||
device_attrs = device.device_state_attributes
|
||||
|
||||
if device.subscription == '555555':
|
||||
self.assertEqual('Vultr Another Server', device.name)
|
||||
assert 'Vultr Another Server' == device.name
|
||||
tested += 1
|
||||
|
||||
if device.name == 'A Server':
|
||||
self.assertEqual(True, device.is_on)
|
||||
self.assertEqual('on', device.state)
|
||||
self.assertEqual('mdi:server', device.icon)
|
||||
self.assertEqual('1000',
|
||||
device_attrs[ATTR_ALLOWED_BANDWIDTH])
|
||||
self.assertEqual('yes',
|
||||
device_attrs[ATTR_AUTO_BACKUPS])
|
||||
self.assertEqual('123.123.123.123',
|
||||
device_attrs[ATTR_IPV4_ADDRESS])
|
||||
self.assertEqual('10.05',
|
||||
device_attrs[ATTR_COST_PER_MONTH])
|
||||
self.assertEqual('2013-12-19 14:45:41',
|
||||
device_attrs[ATTR_CREATED_AT])
|
||||
self.assertEqual('576965',
|
||||
device_attrs[ATTR_SUBSCRIPTION_ID])
|
||||
assert device.is_on is True
|
||||
assert 'on' == device.state
|
||||
assert 'mdi:server' == device.icon
|
||||
assert '1000' == \
|
||||
device_attrs[ATTR_ALLOWED_BANDWIDTH]
|
||||
assert 'yes' == \
|
||||
device_attrs[ATTR_AUTO_BACKUPS]
|
||||
assert '123.123.123.123' == \
|
||||
device_attrs[ATTR_IPV4_ADDRESS]
|
||||
assert '10.05' == \
|
||||
device_attrs[ATTR_COST_PER_MONTH]
|
||||
assert '2013-12-19 14:45:41' == \
|
||||
device_attrs[ATTR_CREATED_AT]
|
||||
assert '576965' == \
|
||||
device_attrs[ATTR_SUBSCRIPTION_ID]
|
||||
tested += 1
|
||||
|
||||
elif device.name == 'Failed Server':
|
||||
self.assertEqual(False, device.is_on)
|
||||
self.assertEqual('off', device.state)
|
||||
self.assertEqual('mdi:server-off', device.icon)
|
||||
self.assertEqual('1000',
|
||||
device_attrs[ATTR_ALLOWED_BANDWIDTH])
|
||||
self.assertEqual('no',
|
||||
device_attrs[ATTR_AUTO_BACKUPS])
|
||||
self.assertEqual('192.168.100.50',
|
||||
device_attrs[ATTR_IPV4_ADDRESS])
|
||||
self.assertEqual('73.25',
|
||||
device_attrs[ATTR_COST_PER_MONTH])
|
||||
self.assertEqual('2014-10-13 14:45:41',
|
||||
device_attrs[ATTR_CREATED_AT])
|
||||
self.assertEqual('123456',
|
||||
device_attrs[ATTR_SUBSCRIPTION_ID])
|
||||
assert device.is_on is False
|
||||
assert 'off' == device.state
|
||||
assert 'mdi:server-off' == device.icon
|
||||
assert '1000' == \
|
||||
device_attrs[ATTR_ALLOWED_BANDWIDTH]
|
||||
assert 'no' == \
|
||||
device_attrs[ATTR_AUTO_BACKUPS]
|
||||
assert '192.168.100.50' == \
|
||||
device_attrs[ATTR_IPV4_ADDRESS]
|
||||
assert '73.25' == \
|
||||
device_attrs[ATTR_COST_PER_MONTH]
|
||||
assert '2014-10-13 14:45:41' == \
|
||||
device_attrs[ATTR_CREATED_AT]
|
||||
assert '123456' == \
|
||||
device_attrs[ATTR_SUBSCRIPTION_ID]
|
||||
tested += 1
|
||||
|
||||
self.assertEqual(4, tested)
|
||||
assert 4 == tested
|
||||
|
||||
@requests_mock.Mocker()
|
||||
def test_turn_on(self, mock):
|
||||
@@ -140,7 +140,7 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
||||
device.turn_on()
|
||||
|
||||
# Turn on
|
||||
self.assertEqual(1, mock_start.call_count)
|
||||
assert 1 == mock_start.call_count
|
||||
|
||||
@requests_mock.Mocker()
|
||||
def test_turn_off(self, mock):
|
||||
@@ -154,7 +154,7 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
||||
device.turn_off()
|
||||
|
||||
# Turn off
|
||||
self.assertEqual(1, mock_halt.call_count)
|
||||
assert 1 == mock_halt.call_count
|
||||
|
||||
def test_invalid_switch_config(self):
|
||||
"""Test config type failures."""
|
||||
@@ -184,7 +184,7 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
||||
self.add_entities,
|
||||
None)
|
||||
|
||||
self.assertIsNotNone(no_subs_setup)
|
||||
assert no_subs_setup is not None
|
||||
|
||||
bad_conf = {
|
||||
CONF_NAME: "Missing Server",
|
||||
@@ -196,4 +196,4 @@ class TestVultrSwitchSetup(unittest.TestCase):
|
||||
self.add_entities,
|
||||
None)
|
||||
|
||||
self.assertIsNotNone(wrong_subs_setup)
|
||||
assert wrong_subs_setup is not None
|
||||
|
||||
@@ -47,16 +47,16 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
"""Test with valid hostname."""
|
||||
global TEST_STATE
|
||||
TEST_STATE = False
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'wake_on_lan',
|
||||
'mac_address': '00-01-02-03-04-05',
|
||||
'host': 'validhostname',
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
TEST_STATE = True
|
||||
|
||||
@@ -64,13 +64,13 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'switch.wake_on_lan')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
@patch('wakeonlan.send_magic_packet', new=send_magic_packet)
|
||||
@patch('subprocess.call', new=call)
|
||||
@@ -79,16 +79,16 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
"""Test with valid hostname on windows."""
|
||||
global TEST_STATE
|
||||
TEST_STATE = False
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'wake_on_lan',
|
||||
'mac_address': '00-01-02-03-04-05',
|
||||
'host': 'validhostname',
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
TEST_STATE = True
|
||||
|
||||
@@ -96,33 +96,33 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
@patch('wakeonlan.send_magic_packet', new=send_magic_packet)
|
||||
@patch('subprocess.call', new=call)
|
||||
def test_minimal_config(self):
|
||||
"""Test with minimal config."""
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'wake_on_lan',
|
||||
'mac_address': '00-01-02-03-04-05',
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
@patch('wakeonlan.send_magic_packet', new=send_magic_packet)
|
||||
@patch('subprocess.call', new=call)
|
||||
def test_broadcast_config(self):
|
||||
"""Test with broadcast address config."""
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'wake_on_lan',
|
||||
'mac_address': '00-01-02-03-04-05',
|
||||
'broadcast_address': '255.255.255.255',
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
common.turn_on(self.hass, 'switch.wake_on_lan')
|
||||
self.hass.block_till_done()
|
||||
@@ -133,7 +133,7 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
"""Test with turn off script."""
|
||||
global TEST_STATE
|
||||
TEST_STATE = False
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'wake_on_lan',
|
||||
'mac_address': '00-01-02-03-04-05',
|
||||
@@ -142,11 +142,11 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
'service': 'shell_command.turn_off_TARGET',
|
||||
},
|
||||
}
|
||||
}))
|
||||
})
|
||||
calls = mock_service(self.hass, 'shell_command', 'turn_off_TARGET')
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
TEST_STATE = True
|
||||
|
||||
@@ -154,7 +154,7 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
assert len(calls) == 0
|
||||
|
||||
TEST_STATE = False
|
||||
@@ -163,7 +163,7 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
assert len(calls) == 1
|
||||
|
||||
@patch('wakeonlan.send_magic_packet', new=send_magic_packet)
|
||||
@@ -173,16 +173,16 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
"""Test with invalid hostname on windows."""
|
||||
global TEST_STATE
|
||||
TEST_STATE = False
|
||||
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
'switch': {
|
||||
'platform': 'wake_on_lan',
|
||||
'mac_address': '00-01-02-03-04-05',
|
||||
'host': 'invalidhostname',
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
TEST_STATE = True
|
||||
|
||||
@@ -190,4 +190,4 @@ class TestWOLSwitch(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.wake_on_lan')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
Reference in New Issue
Block a user