mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Hue: Use the currently active color mode (#13376)
* Hue: Use the currently active color mode * Round hue/sat colors before reporting to API * .gitignore cache fix
This commit is contained in:
parent
553920780f
commit
2497dd5e33
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,6 +22,7 @@ Icon
|
||||
|
||||
# pytest
|
||||
.pytest_cache
|
||||
.cache
|
||||
|
||||
# GITHUB Proposed Python stuff:
|
||||
*.py[cod]
|
||||
|
@ -501,6 +501,10 @@ class Light(ToggleEntity):
|
||||
*data[ATTR_HS_COLOR])
|
||||
data[ATTR_XY_COLOR] = color_util.color_hs_to_xy(
|
||||
*data[ATTR_HS_COLOR])
|
||||
data[ATTR_HS_COLOR] = (
|
||||
round(data[ATTR_HS_COLOR][0], 3),
|
||||
round(data[ATTR_HS_COLOR][1], 3),
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
|
@ -225,9 +225,20 @@ class HueLight(Light):
|
||||
return self.light.action.get('bri')
|
||||
return self.light.state.get('bri')
|
||||
|
||||
@property
|
||||
def _color_mode(self):
|
||||
"""Return the hue color mode."""
|
||||
if self.is_group:
|
||||
return self.light.action.get('colormode')
|
||||
return self.light.state.get('colormode')
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
"""Return the hs color value."""
|
||||
# Don't return hue/sat if in color temperature mode
|
||||
if self._color_mode == "ct":
|
||||
return None
|
||||
|
||||
if self.is_group:
|
||||
return (
|
||||
self.light.action.get('hue') / 65535 * 360,
|
||||
@ -241,6 +252,10 @@ class HueLight(Light):
|
||||
@property
|
||||
def color_temp(self):
|
||||
"""Return the CT color value."""
|
||||
# Don't return color temperature unless in color temperature mode
|
||||
if self._color_mode != "ct":
|
||||
return None
|
||||
|
||||
if self.is_group:
|
||||
return self.light.action.get('ct')
|
||||
return self.light.state.get('ct')
|
||||
|
@ -227,13 +227,48 @@ async def test_lights(hass, mock_bridge):
|
||||
assert lamp_1 is not None
|
||||
assert lamp_1.state == 'on'
|
||||
assert lamp_1.attributes['brightness'] == 144
|
||||
assert lamp_1.attributes['color_temp'] == 467
|
||||
assert lamp_1.attributes['hs_color'] == (71.896, 83.137)
|
||||
|
||||
lamp_2 = hass.states.get('light.hue_lamp_2')
|
||||
assert lamp_2 is not None
|
||||
assert lamp_2.state == 'off'
|
||||
|
||||
|
||||
async def test_lights_color_mode(hass, mock_bridge):
|
||||
"""Test that lights only report appropriate color mode."""
|
||||
mock_bridge.mock_light_responses.append(LIGHT_RESPONSE)
|
||||
await setup_bridge(hass, mock_bridge)
|
||||
|
||||
lamp_1 = hass.states.get('light.hue_lamp_1')
|
||||
assert lamp_1 is not None
|
||||
assert lamp_1.state == 'on'
|
||||
assert lamp_1.attributes['brightness'] == 144
|
||||
assert lamp_1.attributes['hs_color'] == (71.896, 83.137)
|
||||
assert 'color_temp' not in lamp_1.attributes
|
||||
|
||||
new_light1_on = LIGHT_1_ON.copy()
|
||||
new_light1_on['state'] = new_light1_on['state'].copy()
|
||||
new_light1_on['state']['colormode'] = 'ct'
|
||||
mock_bridge.mock_light_responses.append({
|
||||
"1": new_light1_on,
|
||||
})
|
||||
mock_bridge.mock_group_responses.append({})
|
||||
|
||||
# Calling a service will trigger the updates to run
|
||||
await hass.services.async_call('light', 'turn_on', {
|
||||
'entity_id': 'light.hue_lamp_2'
|
||||
}, blocking=True)
|
||||
# 2x light update, 1 turn on request
|
||||
assert len(mock_bridge.mock_requests) == 3
|
||||
|
||||
lamp_1 = hass.states.get('light.hue_lamp_1')
|
||||
assert lamp_1 is not None
|
||||
assert lamp_1.state == 'on'
|
||||
assert lamp_1.attributes['brightness'] == 144
|
||||
assert lamp_1.attributes['color_temp'] == 467
|
||||
assert 'hs_color' not in lamp_1.attributes
|
||||
|
||||
|
||||
async def test_groups(hass, mock_bridge):
|
||||
"""Test the update_lights function with some lights."""
|
||||
mock_bridge.allow_groups = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user