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:
parent
6b059489a6
commit
89c7c80e42
57 changed files with 898 additions and 965 deletions
|
@ -188,23 +188,25 @@ class TestLight(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
_, data = dev1.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
{light.ATTR_TRANSITION: 10,
|
||||
light.ATTR_BRIGHTNESS: 20,
|
||||
light.ATTR_RGB_COLOR: (0, 0, 255)},
|
||||
data)
|
||||
self.assertEqual({
|
||||
light.ATTR_TRANSITION: 10,
|
||||
light.ATTR_BRIGHTNESS: 20,
|
||||
light.ATTR_HS_COLOR: (240, 100),
|
||||
}, data)
|
||||
|
||||
_, data = dev2.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
{light.ATTR_RGB_COLOR: (255, 255, 255),
|
||||
light.ATTR_WHITE_VALUE: 255},
|
||||
data)
|
||||
self.assertEqual({
|
||||
light.ATTR_HS_COLOR: (0, 0),
|
||||
light.ATTR_WHITE_VALUE: 255,
|
||||
}, data)
|
||||
|
||||
_, data = dev3.last_call('turn_on')
|
||||
self.assertEqual({light.ATTR_XY_COLOR: (.4, .6)}, data)
|
||||
self.assertEqual({
|
||||
light.ATTR_HS_COLOR: (71.059, 100),
|
||||
}, data)
|
||||
|
||||
# One of the light profiles
|
||||
prof_name, prof_x, prof_y, prof_bri = 'relax', 0.5119, 0.4147, 144
|
||||
prof_name, prof_h, prof_s, prof_bri = 'relax', 35.932, 69.412, 144
|
||||
|
||||
# Test light profiles
|
||||
light.turn_on(self.hass, dev1.entity_id, profile=prof_name)
|
||||
|
@ -216,16 +218,16 @@ class TestLight(unittest.TestCase):
|
|||
self.hass.block_till_done()
|
||||
|
||||
_, data = dev1.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
{light.ATTR_BRIGHTNESS: prof_bri,
|
||||
light.ATTR_XY_COLOR: (prof_x, prof_y)},
|
||||
data)
|
||||
self.assertEqual({
|
||||
light.ATTR_BRIGHTNESS: prof_bri,
|
||||
light.ATTR_HS_COLOR: (prof_h, prof_s),
|
||||
}, data)
|
||||
|
||||
_, data = dev2.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
{light.ATTR_BRIGHTNESS: 100,
|
||||
light.ATTR_XY_COLOR: (.5119, .4147)},
|
||||
data)
|
||||
self.assertEqual({
|
||||
light.ATTR_BRIGHTNESS: 100,
|
||||
light.ATTR_HS_COLOR: (prof_h, prof_s),
|
||||
}, data)
|
||||
|
||||
# Test bad data
|
||||
light.turn_on(self.hass)
|
||||
|
@ -301,15 +303,16 @@ class TestLight(unittest.TestCase):
|
|||
|
||||
_, data = dev1.last_call('turn_on')
|
||||
|
||||
self.assertEqual(
|
||||
{light.ATTR_XY_COLOR: (.4, .6), light.ATTR_BRIGHTNESS: 100},
|
||||
data)
|
||||
self.assertEqual({
|
||||
light.ATTR_HS_COLOR: (71.059, 100),
|
||||
light.ATTR_BRIGHTNESS: 100
|
||||
}, data)
|
||||
|
||||
|
||||
async def test_intent_set_color(hass):
|
||||
"""Test the set color intent."""
|
||||
hass.states.async_set('light.hello_2', 'off', {
|
||||
ATTR_SUPPORTED_FEATURES: light.SUPPORT_RGB_COLOR
|
||||
ATTR_SUPPORTED_FEATURES: light.SUPPORT_COLOR
|
||||
})
|
||||
hass.states.async_set('switch.hello', 'off')
|
||||
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
|
||||
|
@ -364,7 +367,7 @@ async def test_intent_set_color_and_brightness(hass):
|
|||
"""Test the set color intent."""
|
||||
hass.states.async_set('light.hello_2', 'off', {
|
||||
ATTR_SUPPORTED_FEATURES: (
|
||||
light.SUPPORT_RGB_COLOR | light.SUPPORT_BRIGHTNESS)
|
||||
light.SUPPORT_COLOR | light.SUPPORT_BRIGHTNESS)
|
||||
})
|
||||
hass.states.async_set('switch.hello', 'off')
|
||||
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue