Disallow ambiguous color descriptors in the light.turn_on schema (#7765)
* Disallow ambiguous color descriptors in the light.turn_on schema * Update tests
This commit is contained in:
parent
9480f41210
commit
e2cfdbff06
5 changed files with 39 additions and 24 deletions
|
@ -206,10 +206,10 @@ class TestLight(unittest.TestCase):
|
|||
|
||||
# Test light profiles
|
||||
light.turn_on(self.hass, dev1.entity_id, profile=prof_name)
|
||||
# Specify a profile and attributes to overwrite it
|
||||
# Specify a profile and a brightness attribute to overwrite it
|
||||
light.turn_on(
|
||||
self.hass, dev2.entity_id,
|
||||
profile=prof_name, brightness=100, xy_color=(.4, .6))
|
||||
profile=prof_name, brightness=100)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
|
@ -222,10 +222,10 @@ class TestLight(unittest.TestCase):
|
|||
_, data = dev2.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
{light.ATTR_BRIGHTNESS: 100,
|
||||
light.ATTR_XY_COLOR: (.4, .6)},
|
||||
light.ATTR_XY_COLOR: (.5119, .4147)},
|
||||
data)
|
||||
|
||||
# Test shitty data
|
||||
# Test bad data
|
||||
light.turn_on(self.hass)
|
||||
light.turn_on(self.hass, dev1.entity_id, profile="nonexisting")
|
||||
light.turn_on(self.hass, dev2.entity_id, xy_color=["bla-di-bla", 5])
|
||||
|
@ -245,7 +245,10 @@ class TestLight(unittest.TestCase):
|
|||
# faulty attributes will not trigger a service call
|
||||
light.turn_on(
|
||||
self.hass, dev1.entity_id,
|
||||
profile=prof_name, brightness='bright', rgb_color='yellowish')
|
||||
profile=prof_name, brightness='bright')
|
||||
light.turn_on(
|
||||
self.hass, dev1.entity_id,
|
||||
rgb_color='yellowish')
|
||||
light.turn_on(
|
||||
self.hass, dev2.entity_id,
|
||||
white_value='high')
|
||||
|
|
|
@ -491,8 +491,10 @@ class TestLightMQTT(unittest.TestCase):
|
|||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
self.mock_publish.reset_mock()
|
||||
light.turn_on(self.hass, 'light.test',
|
||||
brightness=50, xy_color=[0.123, 0.123])
|
||||
light.turn_on(self.hass, 'light.test', rgb_color=[75, 75, 75],
|
||||
brightness=50, white_value=80, xy_color=[0.123, 0.123])
|
||||
white_value=80)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.mock_publish().async_publish.assert_has_calls([
|
||||
|
|
|
@ -294,7 +294,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
light.turn_on(self.hass, 'light.test', rgb_color=[75, 75, 75],
|
||||
light.turn_on(self.hass, 'light.test',
|
||||
brightness=50, color_temp=155, effect='colorloop',
|
||||
white_value=170)
|
||||
self.hass.block_till_done()
|
||||
|
@ -308,15 +308,11 @@ class TestLightMQTTJSON(unittest.TestCase):
|
|||
self.assertEqual(50, message_json["brightness"])
|
||||
self.assertEqual(155, message_json["color_temp"])
|
||||
self.assertEqual('colorloop', message_json["effect"])
|
||||
self.assertEqual(75, message_json["color"]["r"])
|
||||
self.assertEqual(75, message_json["color"]["g"])
|
||||
self.assertEqual(75, message_json["color"]["b"])
|
||||
self.assertEqual(170, message_json["white_value"])
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual((75, 75, 75), state.attributes['rgb_color'])
|
||||
self.assertEqual(50, state.attributes['brightness'])
|
||||
self.assertEqual(155, state.attributes['color_temp'])
|
||||
self.assertEqual('colorloop', state.attributes['effect'])
|
||||
|
|
|
@ -245,19 +245,27 @@ class TestLightMQTTTemplate(unittest.TestCase):
|
|||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
# turn on the light with brightness, color, color temp and white val
|
||||
# turn on the light with brightness, color
|
||||
light.turn_on(self.hass, 'light.test', brightness=50,
|
||||
rgb_color=[75, 75, 75], color_temp=200, white_value=139)
|
||||
rgb_color=[75, 75, 75])
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.mock_calls[-2][1][0])
|
||||
self.assertEqual(2, self.mock_publish.mock_calls[-2][1][2])
|
||||
self.assertEqual(False, self.mock_publish.mock_calls[-2][1][3])
|
||||
|
||||
# check the payload
|
||||
payload = self.mock_publish.mock_calls[-2][1][1]
|
||||
self.assertEqual('on,50,200,139,75-75-75', payload)
|
||||
self.assertEqual('on,50,,,75-75-75', payload)
|
||||
|
||||
# turn on the light with color temp and white val
|
||||
light.turn_on(self.hass, 'light.test', color_temp=200, white_value=139)
|
||||
self.hass.block_till_done()
|
||||
|
||||
payload = self.mock_publish.mock_calls[-2][1][1]
|
||||
self.assertEqual('on,,200,139,--', payload)
|
||||
|
||||
self.assertEqual(2, self.mock_publish.mock_calls[-2][1][2])
|
||||
self.assertEqual(False, self.mock_publish.mock_calls[-2][1][3])
|
||||
|
||||
# check the state
|
||||
state = self.hass.states.get('light.test')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue