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
|
@ -127,7 +127,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
'name': 'test',
|
||||
}
|
||||
})
|
||||
self.assertIsNone(self.hass.states.get('light.test'))
|
||||
assert self.hass.states.get('light.test') is None
|
||||
|
||||
def test_no_color_brightness_color_temp_white_val_if_no_topics(self):
|
||||
"""Test for no RGB, brightness, color temp, effect, white val or XY."""
|
||||
|
@ -141,28 +141,28 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
self.assertIsNone(state.attributes.get('effect'))
|
||||
self.assertIsNone(state.attributes.get('white_value'))
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('hs_color'))
|
||||
assert STATE_OFF == state.state
|
||||
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
assert state.attributes.get('effect') is None
|
||||
assert state.attributes.get('white_value') is None
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('hs_color') is None
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
self.assertIsNone(state.attributes.get('effect'))
|
||||
self.assertIsNone(state.attributes.get('white_value'))
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('hs_color'))
|
||||
assert STATE_ON == state.state
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
assert state.attributes.get('effect') is None
|
||||
assert state.attributes.get('white_value') is None
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('hs_color') is None
|
||||
|
||||
def test_controlling_state_via_topic(self):
|
||||
"""Test the controlling of the state via topic."""
|
||||
|
@ -184,16 +184,16 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertEqual(191, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
self.assertIsNone(state.attributes.get('effect'))
|
||||
self.assertIsNone(state.attributes.get('white_value'))
|
||||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('hs_color'))
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert 191 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
assert state.attributes.get('effect') is None
|
||||
assert state.attributes.get('white_value') is None
|
||||
assert state.attributes.get('xy_color') is None
|
||||
assert state.attributes.get('hs_color') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
# Turn on the light, full white
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
|
@ -206,21 +206,21 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
self.assertEqual(155, state.attributes.get('color_temp'))
|
||||
self.assertEqual('colorloop', state.attributes.get('effect'))
|
||||
self.assertEqual(150, state.attributes.get('white_value'))
|
||||
self.assertEqual((0.323, 0.329), state.attributes.get('xy_color'))
|
||||
self.assertEqual((0.0, 0.0), state.attributes.get('hs_color'))
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 155 == state.attributes.get('color_temp')
|
||||
assert 'colorloop' == state.attributes.get('effect')
|
||||
assert 150 == state.attributes.get('white_value')
|
||||
assert (0.323, 0.329) == state.attributes.get('xy_color')
|
||||
assert (0.0, 0.0) == state.attributes.get('hs_color')
|
||||
|
||||
# Turn the light off
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"OFF"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -229,8 +229,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(100,
|
||||
light_state.attributes['brightness'])
|
||||
assert 100 == \
|
||||
light_state.attributes['brightness']
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -238,8 +238,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual((255, 255, 255),
|
||||
light_state.attributes.get('rgb_color'))
|
||||
assert (255, 255, 255) == \
|
||||
light_state.attributes.get('rgb_color')
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -247,8 +247,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual((0.141, 0.14),
|
||||
light_state.attributes.get('xy_color'))
|
||||
assert (0.141, 0.14) == \
|
||||
light_state.attributes.get('xy_color')
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -256,8 +256,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual((180.0, 50.0),
|
||||
light_state.attributes.get('hs_color'))
|
||||
assert (180.0, 50.0) == \
|
||||
light_state.attributes.get('hs_color')
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -265,7 +265,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual(155, light_state.attributes.get('color_temp'))
|
||||
assert 155 == light_state.attributes.get('color_temp')
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -273,7 +273,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual('colorloop', light_state.attributes.get('effect'))
|
||||
assert 'colorloop' == light_state.attributes.get('effect')
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
'{"state":"ON",'
|
||||
|
@ -281,7 +281,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual(155, light_state.attributes.get('white_value'))
|
||||
assert 155 == light_state.attributes.get('white_value')
|
||||
|
||||
def test_sending_mqtt_commands_and_optimistic(self):
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
|
@ -309,14 +309,14 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(95, state.attributes.get('brightness'))
|
||||
self.assertEqual((100, 100), state.attributes.get('hs_color'))
|
||||
self.assertEqual('random', state.attributes.get('effect'))
|
||||
self.assertEqual(100, state.attributes.get('color_temp'))
|
||||
self.assertEqual(50, state.attributes.get('white_value'))
|
||||
self.assertEqual(191, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_ON == state.state
|
||||
assert 95 == state.attributes.get('brightness')
|
||||
assert (100, 100) == state.attributes.get('hs_color')
|
||||
assert 'random' == state.attributes.get('effect')
|
||||
assert 100 == state.attributes.get('color_temp')
|
||||
assert 50 == state.attributes.get('white_value')
|
||||
assert 191 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
common.turn_on(self.hass, 'light.test')
|
||||
self.hass.block_till_done()
|
||||
|
@ -325,7 +325,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
'test_light_rgb/set', '{"state": "ON"}', 2, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
assert STATE_ON == state.state
|
||||
|
||||
common.turn_off(self.hass, 'light.test')
|
||||
self.hass.block_till_done()
|
||||
|
@ -334,61 +334,59 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
'test_light_rgb/set', '{"state": "OFF"}', 2, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
assert STATE_OFF == state.state
|
||||
|
||||
common.turn_on(self.hass, 'light.test',
|
||||
brightness=50, color_temp=155, effect='colorloop',
|
||||
white_value=170)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
||||
self.assertEqual(2,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
||||
self.assertEqual(False,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
||||
assert 'test_light_rgb/set' == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||
assert 2 == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||
# Get the sent message
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||
self.assertEqual(50, message_json["brightness"])
|
||||
self.assertEqual(155, message_json["color_temp"])
|
||||
self.assertEqual('colorloop', message_json["effect"])
|
||||
self.assertEqual(170, message_json["white_value"])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
assert 50 == message_json["brightness"]
|
||||
assert 155 == message_json["color_temp"]
|
||||
assert 'colorloop' == message_json["effect"]
|
||||
assert 170 == message_json["white_value"]
|
||||
assert "ON" == message_json["state"]
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(50, state.attributes['brightness'])
|
||||
self.assertEqual(155, state.attributes['color_temp'])
|
||||
self.assertEqual('colorloop', state.attributes['effect'])
|
||||
self.assertEqual(170, state.attributes['white_value'])
|
||||
assert STATE_ON == state.state
|
||||
assert 50 == state.attributes['brightness']
|
||||
assert 155 == state.attributes['color_temp']
|
||||
assert 'colorloop' == state.attributes['effect']
|
||||
assert 170 == state.attributes['white_value']
|
||||
|
||||
# Test a color command
|
||||
common.turn_on(self.hass, 'light.test',
|
||||
brightness=50, hs_color=(125, 100))
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
||||
self.assertEqual(2,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
||||
self.assertEqual(False,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
||||
assert 'test_light_rgb/set' == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||
assert 2 == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||
# Get the sent message
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[1][1][1])
|
||||
self.assertEqual(50, message_json["brightness"])
|
||||
self.assertEqual({
|
||||
assert 50 == message_json["brightness"]
|
||||
assert {
|
||||
'r': 0,
|
||||
'g': 255,
|
||||
'b': 21,
|
||||
}, message_json["color"])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
} == message_json["color"]
|
||||
assert "ON" == message_json["state"]
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(50, state.attributes['brightness'])
|
||||
self.assertEqual((125, 100), state.attributes['hs_color'])
|
||||
assert STATE_ON == state.state
|
||||
assert 50 == state.attributes['brightness']
|
||||
assert (125, 100) == state.attributes['hs_color']
|
||||
|
||||
def test_sending_hs_color(self):
|
||||
"""Test light.turn_on with hs color sends hs color parameters."""
|
||||
|
@ -406,11 +404,11 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
self.assertEqual({
|
||||
assert "ON" == message_json["state"]
|
||||
assert {
|
||||
'h': 180.0,
|
||||
's': 50.0,
|
||||
}, message_json["color"])
|
||||
} == message_json["color"]
|
||||
|
||||
def test_flash_short_and_long(self):
|
||||
"""Test for flash length being sent when included."""
|
||||
|
@ -427,39 +425,37 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
||||
assert STATE_OFF == state.state
|
||||
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
|
||||
common.turn_on(self.hass, 'light.test', flash="short")
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
||||
self.assertEqual(0,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
||||
self.assertEqual(False,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
||||
assert 'test_light_rgb/set' == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||
assert 0 == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||
# Get the sent message
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||
self.assertEqual(5, message_json["flash"])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
assert 5 == message_json["flash"]
|
||||
assert "ON" == message_json["state"]
|
||||
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
common.turn_on(self.hass, 'light.test', flash="long")
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
||||
self.assertEqual(0,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
||||
self.assertEqual(False,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
||||
assert 'test_light_rgb/set' == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||
assert 0 == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||
# Get the sent message
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||
self.assertEqual(15, message_json["flash"])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
assert 15 == message_json["flash"]
|
||||
assert "ON" == message_json["state"]
|
||||
|
||||
def test_transition(self):
|
||||
"""Test for transition time being sent when included."""
|
||||
|
@ -474,39 +470,37 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
||||
assert STATE_OFF == state.state
|
||||
assert 40 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
|
||||
common.turn_on(self.hass, 'light.test', transition=10)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0])
|
||||
self.assertEqual(0,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2])
|
||||
self.assertEqual(False,
|
||||
self.mock_publish.async_publish.mock_calls[0][1][3])
|
||||
assert 'test_light_rgb/set' == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][0]
|
||||
assert 0 == \
|
||||
self.mock_publish.async_publish.mock_calls[0][1][2]
|
||||
assert self.mock_publish.async_publish.mock_calls[0][1][3] is False
|
||||
# Get the sent message
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[0][1][1])
|
||||
self.assertEqual(10, message_json["transition"])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
assert 10 == message_json["transition"]
|
||||
assert "ON" == message_json["state"]
|
||||
|
||||
# Transition back off
|
||||
common.turn_off(self.hass, 'light.test', transition=10)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.async_publish.mock_calls[1][1][0])
|
||||
self.assertEqual(0,
|
||||
self.mock_publish.async_publish.mock_calls[1][1][2])
|
||||
self.assertEqual(False,
|
||||
self.mock_publish.async_publish.mock_calls[1][1][3])
|
||||
assert 'test_light_rgb/set' == \
|
||||
self.mock_publish.async_publish.mock_calls[1][1][0]
|
||||
assert 0 == \
|
||||
self.mock_publish.async_publish.mock_calls[1][1][2]
|
||||
assert self.mock_publish.async_publish.mock_calls[1][1][3] is False
|
||||
# Get the sent message
|
||||
message_json = json.loads(
|
||||
self.mock_publish.async_publish.mock_calls[1][1][1])
|
||||
self.assertEqual(10, message_json["transition"])
|
||||
self.assertEqual("OFF", message_json["state"])
|
||||
assert 10 == message_json["transition"]
|
||||
assert "OFF" == message_json["state"]
|
||||
|
||||
def test_brightness_scale(self):
|
||||
"""Test for brightness scaling."""
|
||||
|
@ -522,9 +516,9 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
# Turn on the light
|
||||
fire_mqtt_message(self.hass, 'test_light_bright_scale',
|
||||
|
@ -532,8 +526,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
|
||||
# Turn on the light with brightness
|
||||
fire_mqtt_message(self.hass, 'test_light_bright_scale',
|
||||
|
@ -542,8 +536,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
|
||||
def test_invalid_color_brightness_and_white_values(self):
|
||||
"""Test that invalid color/brightness/white values are ignored."""
|
||||
|
@ -561,12 +555,12 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
})
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
self.assertEqual(185, state.attributes.get(ATTR_SUPPORTED_FEATURES))
|
||||
self.assertIsNone(state.attributes.get('rgb_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
self.assertIsNone(state.attributes.get('white_value'))
|
||||
self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
assert STATE_OFF == state.state
|
||||
assert 185 == state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
||||
assert state.attributes.get('rgb_color') is None
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('white_value') is None
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
# Turn on the light
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
|
@ -577,10 +571,10 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
self.assertEqual(255, state.attributes.get('white_value'))
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
|
||||
# Bad color values
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
|
@ -590,8 +584,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
|
||||
# Color should not have changed
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
|
||||
assert STATE_ON == state.state
|
||||
assert (255, 255, 255) == state.attributes.get('rgb_color')
|
||||
|
||||
# Bad brightness values
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
|
@ -601,8 +595,8 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
|
||||
# Brightness should not have changed
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('brightness')
|
||||
|
||||
# Bad white value
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb',
|
||||
|
@ -612,12 +606,12 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
|
||||
# White value should not have changed
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(255, state.attributes.get('white_value'))
|
||||
assert STATE_ON == state.state
|
||||
assert 255 == state.attributes.get('white_value')
|
||||
|
||||
def test_default_availability_payload(self):
|
||||
"""Test availability by default payload with defined topic."""
|
||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
||||
assert setup_component(self.hass, light.DOMAIN, {
|
||||
light.DOMAIN: {
|
||||
'platform': 'mqtt_json',
|
||||
'name': 'test',
|
||||
|
@ -625,26 +619,26 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
'command_topic': 'test_light_rgb/set',
|
||||
'availability_topic': 'availability-topic'
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('light.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('light.test')
|
||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'offline')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
def test_custom_availability_payload(self):
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
self.assertTrue(setup_component(self.hass, light.DOMAIN, {
|
||||
assert setup_component(self.hass, light.DOMAIN, {
|
||||
light.DOMAIN: {
|
||||
'platform': 'mqtt_json',
|
||||
'name': 'test',
|
||||
|
@ -654,22 +648,22 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
'payload_available': 'good',
|
||||
'payload_not_available': 'nogood'
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('light.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('light.test')
|
||||
self.assertNotEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE != state.state
|
||||
|
||||
fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||
assert STATE_UNAVAILABLE == state.state
|
||||
|
||||
|
||||
async def test_discovery_removal(hass, mqtt_mock, caplog):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue