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 authored and Paulus Schoutsen committed 2018-03-18 15:00:29 -07:00
1 parent 6b059489a6
commit 89c7c80e42
57 files changed
+898 -965

No files matched your search

+10 -38
View File
@@ -20,8 +20,7 @@ async def test_default_state(hass):
assert state.state == 'unavailable'
assert state.attributes['supported_features'] == 0
assert state.attributes.get('brightness') is None
assert state.attributes.get('rgb_color') is None
assert state.attributes.get('xy_color') is None
assert state.attributes.get('hs_color') is None
assert state.attributes.get('color_temp') is None
assert state.attributes.get('white_value') is None
assert state.attributes.get('effect_list') is None
@@ -85,61 +84,32 @@ async def test_brightness(hass):
assert state.attributes['brightness'] == 100
async def test_xy_color(hass):
"""Test XY reporting."""
await async_setup_component(hass, 'light', {'light': {
'platform': 'group', 'entities': ['light.test1', 'light.test2']
}})
hass.states.async_set('light.test1', 'on',
{'xy_color': (1.0, 1.0), 'supported_features': 64})
await hass.async_block_till_done()
state = hass.states.get('light.light_group')
assert state.state == 'on'
assert state.attributes['supported_features'] == 64
assert state.attributes['xy_color'] == (1.0, 1.0)
hass.states.async_set('light.test2', 'on',
{'xy_color': (0.5, 0.5), 'supported_features': 64})
await hass.async_block_till_done()
state = hass.states.get('light.light_group')
assert state.state == 'on'
assert state.attributes['xy_color'] == (0.75, 0.75)
hass.states.async_set('light.test1', 'off',
{'xy_color': (1.0, 1.0), 'supported_features': 64})
await hass.async_block_till_done()
state = hass.states.get('light.light_group')
assert state.state == 'on'
assert state.attributes['xy_color'] == (0.5, 0.5)
async def test_rgb_color(hass):
async def test_color(hass):
"""Test RGB reporting."""
await async_setup_component(hass, 'light', {'light': {
'platform': 'group', 'entities': ['light.test1', 'light.test2']
}})
hass.states.async_set('light.test1', 'on',
{'rgb_color': (255, 0, 0), 'supported_features': 16})
{'hs_color': (0, 100), 'supported_features': 16})
await hass.async_block_till_done()
state = hass.states.get('light.light_group')
assert state.state == 'on'
assert state.attributes['supported_features'] == 16
assert state.attributes['rgb_color'] == (255, 0, 0)
assert state.attributes['hs_color'] == (0, 100)
hass.states.async_set('light.test2', 'on',
{'rgb_color': (255, 255, 255),
{'hs_color': (0, 50),
'supported_features': 16})
await hass.async_block_till_done()
state = hass.states.get('light.light_group')
assert state.attributes['rgb_color'] == (255, 127, 127)
assert state.attributes['hs_color'] == (0, 75)
hass.states.async_set('light.test1', 'off',
{'rgb_color': (255, 0, 0), 'supported_features': 16})
{'hs_color': (0, 0), 'supported_features': 16})
await hass.async_block_till_done()
state = hass.states.get('light.light_group')
assert state.attributes['rgb_color'] == (255, 255, 255)
assert state.attributes['hs_color'] == (0, 50)
async def test_white_value(hass):
@@ -413,5 +383,7 @@ async def test_invalid_service_calls(hass):
}
await grouped_light.async_turn_on(**data)
data['entity_id'] = ['light.test1', 'light.test2']
data.pop('rgb_color')
data.pop('xy_color')
mock_call.assert_called_once_with('light', 'turn_on', data,
blocking=True)