Use hue/sat as internal light color interface (#11288)

* Accept and report both xy and RGB color for lights

* Fix demo light supported_features

* Add new XY color util functions

* Always make color changes available as xy and RGB

* Always expose color as RGB and XY

* Consolidate color supported_features

* Test fixes

* Additional test fix

* Use hue/sat as the hass core color interface

* Tests updates

* Assume MQTT RGB devices need full RGB brightness

* Convert new platforms

* More migration

* Use float for HS API

* Fix backwards conversion for KNX lights

* Adjust limitless min saturation for new scale
This commit is contained in:
Adam Mills 2018-03-18 18:00:29 -04:00 committed by Paulus Schoutsen
parent 6b059489a6
commit 89c7c80e42
57 changed files with 898 additions and 965 deletions

View file

@ -180,7 +180,7 @@ class TestLightMQTTJSON(unittest.TestCase):
state = self.hass.states.get('light.test')
self.assertEqual(STATE_OFF, state.state)
self.assertEqual(255, state.attributes.get(ATTR_SUPPORTED_FEATURES))
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'))
@ -192,8 +192,7 @@ class TestLightMQTTJSON(unittest.TestCase):
# Turn on the light, full white
fire_mqtt_message(self.hass, 'test_light_rgb',
'{"state":"ON",'
'"color":{"r":255,"g":255,"b":255,'
'"x":0.123,"y":0.123},'
'"color":{"r":255,"g":255,"b":255},'
'"brightness":255,'
'"color_temp":155,'
'"effect":"colorloop",'
@ -202,12 +201,12 @@ class TestLightMQTTJSON(unittest.TestCase):
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, 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.123, 0.123], state.attributes.get('xy_color'))
self.assertEqual((0.32, 0.336), state.attributes.get('xy_color'))
# Turn the light off
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"OFF"}')
@ -232,7 +231,7 @@ class TestLightMQTTJSON(unittest.TestCase):
self.hass.block_till_done()
light_state = self.hass.states.get('light.test')
self.assertEqual([125, 125, 125],
self.assertEqual((255, 255, 255),
light_state.attributes.get('rgb_color'))
fire_mqtt_message(self.hass, 'test_light_rgb',
@ -241,7 +240,7 @@ class TestLightMQTTJSON(unittest.TestCase):
self.hass.block_till_done()
light_state = self.hass.states.get('light.test')
self.assertEqual([0.135, 0.135],
self.assertEqual((0.141, 0.14),
light_state.attributes.get('xy_color'))
fire_mqtt_message(self.hass, 'test_light_rgb',
@ -503,7 +502,7 @@ class TestLightMQTTJSON(unittest.TestCase):
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, 255, 255), state.attributes.get('rgb_color'))
self.assertEqual(255, state.attributes.get('brightness'))
self.assertEqual(255, state.attributes.get('white_value'))
@ -516,7 +515,7 @@ 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'))
self.assertEqual((255, 255, 255), state.attributes.get('rgb_color'))
# Bad brightness values
fire_mqtt_message(self.hass, 'test_light_rgb',