Coerce RGB and XY color values to tuples instead of lists.

This commit is contained in:
Jan Harkes 2016-03-31 22:59:18 -04:00
parent 017f47dd2c
commit 4f3dc2ce8b
3 changed files with 14 additions and 12 deletions

View File

@ -87,8 +87,10 @@ LIGHT_TURN_ON_SCHEMA = vol.Schema({
ATTR_PROFILE: str,
ATTR_TRANSITION: VALID_TRANSITION,
ATTR_BRIGHTNESS: vol.All(int, vol.Range(min=0, max=255)),
ATTR_RGB_COLOR: vol.ExactSequence((cv.byte, cv.byte, cv.byte)),
ATTR_XY_COLOR: vol.ExactSequence((cv.small_float, cv.small_float)),
ATTR_RGB_COLOR: vol.All(vol.ExactSequence((cv.byte, cv.byte, cv.byte)),
vol.Coerce(tuple)),
ATTR_XY_COLOR: vol.All(vol.ExactSequence((cv.small_float, cv.small_float)),
vol.Coerce(tuple)),
ATTR_COLOR_TEMP: vol.All(int, vol.Range(min=154, max=500)),
ATTR_FLASH: [FLASH_SHORT, FLASH_LONG],
ATTR_EFFECT: [EFFECT_COLORLOOP, EFFECT_RANDOM, EFFECT_WHITE],
@ -222,7 +224,7 @@ def setup(hass, config):
profile = profiles.get(params.pop(ATTR_PROFILE, None))
if profile:
params.setdefault(ATTR_XY_COLOR, list(profile[:2]))
params.setdefault(ATTR_XY_COLOR, profile[:2])
params.setdefault(ATTR_BRIGHTNESS, profile[2])
for light in target_lights:

View File

@ -170,8 +170,8 @@ class TestLight(unittest.TestCase):
light.turn_on(self.hass, dev1.entity_id,
transition=10, brightness=20)
light.turn_on(
self.hass, dev2.entity_id, rgb_color=[255, 255, 255])
light.turn_on(self.hass, dev3.entity_id, xy_color=[.4, .6])
self.hass, dev2.entity_id, rgb_color=(255, 255, 255))
light.turn_on(self.hass, dev3.entity_id, xy_color=(.4, .6))
self.hass.pool.block_till_done()
@ -182,10 +182,10 @@ class TestLight(unittest.TestCase):
data)
method, data = dev2.last_call('turn_on')
self.assertEquals(data[light.ATTR_RGB_COLOR], [255, 255, 255])
self.assertEquals(data[light.ATTR_RGB_COLOR], (255, 255, 255))
method, data = dev3.last_call('turn_on')
self.assertEqual({light.ATTR_XY_COLOR: [.4, .6]}, data)
self.assertEqual({light.ATTR_XY_COLOR: (.4, .6)}, data)
# One of the light profiles
prof_name, prof_x, prof_y, prof_bri = 'relax', 0.5119, 0.4147, 144
@ -195,20 +195,20 @@ class TestLight(unittest.TestCase):
# Specify a profile and attributes 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, xy_color=(.4, .6))
self.hass.pool.block_till_done()
method, data = dev1.last_call('turn_on')
self.assertEqual(
{light.ATTR_BRIGHTNESS: prof_bri,
light.ATTR_XY_COLOR: [prof_x, prof_y]},
light.ATTR_XY_COLOR: (prof_x, prof_y)},
data)
method, data = dev2.last_call('turn_on')
self.assertEqual(
{light.ATTR_BRIGHTNESS: 100,
light.ATTR_XY_COLOR: [.4, .6]},
light.ATTR_XY_COLOR: (.4, .6)},
data)
# Test shitty data
@ -278,5 +278,5 @@ class TestLight(unittest.TestCase):
method, data = dev1.last_call('turn_on')
self.assertEqual(
{light.ATTR_XY_COLOR: [.4, .6], light.ATTR_BRIGHTNESS: 100},
{light.ATTR_XY_COLOR: (.4, .6), light.ATTR_BRIGHTNESS: 100},
data)

View File

@ -305,7 +305,7 @@ class TestLightMQTT(unittest.TestCase):
state = self.hass.states.get('light.test')
self.assertEqual(STATE_ON, state.state)
self.assertEqual([75, 75, 75], state.attributes['rgb_color'])
self.assertEqual((75, 75, 75), state.attributes['rgb_color'])
self.assertEqual(50, state.attributes['brightness'])
def test_show_brightness_if_only_command_topic(self):