Fix RGB template ordering in MQTT Light (#11362)

* Use different colour channel intensities in tests

Uses a different value for each colour channel in MQTT light tests to
properly differentiate between colour channels.

* Correct ordering of RGB channels in MQTT light
pull/11369/head
Dan Nixon 2017-12-29 14:28:20 +00:00 committed by Martin Hjelmare
parent cfd78f7b02
commit f07a4684e0
3 changed files with 6 additions and 6 deletions

View File

@ -424,7 +424,7 @@ class MqttLight(Light):
tpl = self._templates[CONF_RGB_COMMAND_TEMPLATE]
if tpl:
colors = {'red', 'green', 'blue'}
colors = ('red', 'green', 'blue')
variables = {key: val for key, val in
zip(colors, kwargs[ATTR_RGB_COLOR])}
rgb_color_str = tpl.async_render(variables)

View File

@ -546,17 +546,17 @@ class TestLightMQTT(unittest.TestCase):
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
light.turn_on(self.hass, 'light.test', rgb_color=[255, 255, 255])
light.turn_on(self.hass, 'light.test', rgb_color=[255, 128, 64])
self.hass.block_till_done()
self.mock_publish().async_publish.assert_has_calls([
mock.call('test_light_rgb/set', 'on', 0, False),
mock.call('test_light_rgb/rgb/set', '#ffffff', 0, False),
mock.call('test_light_rgb/rgb/set', '#ff8040', 0, False),
], any_order=True)
state = self.hass.states.get('light.test')
self.assertEqual(STATE_ON, state.state)
self.assertEqual((255, 255, 255), state.attributes['rgb_color'])
self.assertEqual((255, 128, 64), state.attributes['rgb_color'])
def test_show_brightness_if_only_command_topic(self):
"""Test the brightness if only a command topic is present."""

View File

@ -145,12 +145,12 @@ class TestLightMQTTTemplate(unittest.TestCase):
# turn on the light, full white
fire_mqtt_message(self.hass, 'test_light_rgb',
'on,255,145,123,255-255-255,')
'on,255,145,123,255-128-64,')
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, 128, 64], state.attributes.get('rgb_color'))
self.assertEqual(255, state.attributes.get('brightness'))
self.assertEqual(145, state.attributes.get('color_temp'))
self.assertEqual(123, state.attributes.get('white_value'))