mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Improve precision of Hue color state (#14113)
This commit is contained in:
parent
9d1f9fe204
commit
0b350993b5
@ -242,26 +242,16 @@ class HueLight(Light):
|
|||||||
@property
|
@property
|
||||||
def hs_color(self):
|
def hs_color(self):
|
||||||
"""Return the hs color value."""
|
"""Return the hs color value."""
|
||||||
# pylint: disable=redefined-outer-name
|
|
||||||
mode = self._color_mode
|
mode = self._color_mode
|
||||||
|
|
||||||
if mode not in ('hs', 'xy'):
|
|
||||||
return
|
|
||||||
|
|
||||||
source = self.light.action if self.is_group else self.light.state
|
source = self.light.action if self.is_group else self.light.state
|
||||||
|
|
||||||
hue = source.get('hue')
|
if mode == 'xy' and 'xy' in source:
|
||||||
sat = source.get('sat')
|
return color.color_xy_to_hs(*source['xy'])
|
||||||
|
|
||||||
# Sometimes the state will not include valid hue/sat values.
|
if mode == 'hs' and 'hue' in source and 'sat' in source:
|
||||||
# Reported as issue 13434
|
return source['hue'] / 65535 * 360, source['sat'] / 255 * 100
|
||||||
if hue is not None and sat is not None:
|
|
||||||
return hue / 65535 * 360, sat / 255 * 100
|
|
||||||
|
|
||||||
if 'xy' not in source:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
return color.color_xy_to_hs(*source['xy'])
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
|
@ -237,7 +237,7 @@ async def test_lights(hass, mock_bridge):
|
|||||||
assert lamp_1 is not None
|
assert lamp_1 is not None
|
||||||
assert lamp_1.state == 'on'
|
assert lamp_1.state == 'on'
|
||||||
assert lamp_1.attributes['brightness'] == 144
|
assert lamp_1.attributes['brightness'] == 144
|
||||||
assert lamp_1.attributes['hs_color'] == (71.896, 83.137)
|
assert lamp_1.attributes['hs_color'] == (36.067, 69.804)
|
||||||
|
|
||||||
lamp_2 = hass.states.get('light.hue_lamp_2')
|
lamp_2 = hass.states.get('light.hue_lamp_2')
|
||||||
assert lamp_2 is not None
|
assert lamp_2 is not None
|
||||||
@ -253,7 +253,7 @@ async def test_lights_color_mode(hass, mock_bridge):
|
|||||||
assert lamp_1 is not None
|
assert lamp_1 is not None
|
||||||
assert lamp_1.state == 'on'
|
assert lamp_1.state == 'on'
|
||||||
assert lamp_1.attributes['brightness'] == 144
|
assert lamp_1.attributes['brightness'] == 144
|
||||||
assert lamp_1.attributes['hs_color'] == (71.896, 83.137)
|
assert lamp_1.attributes['hs_color'] == (36.067, 69.804)
|
||||||
assert 'color_temp' not in lamp_1.attributes
|
assert 'color_temp' not in lamp_1.attributes
|
||||||
|
|
||||||
new_light1_on = LIGHT_1_ON.copy()
|
new_light1_on = LIGHT_1_ON.copy()
|
||||||
@ -668,19 +668,6 @@ def test_hs_color():
|
|||||||
'colormode': 'xy',
|
'colormode': 'xy',
|
||||||
'hue': 1234,
|
'hue': 1234,
|
||||||
'sat': 123,
|
'sat': 123,
|
||||||
}),
|
|
||||||
request_bridge_update=None,
|
|
||||||
bridge=Mock(),
|
|
||||||
is_group=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert light.hs_color == (1234 / 65535 * 360, 123 / 255 * 100)
|
|
||||||
|
|
||||||
light = hue_light.HueLight(
|
|
||||||
light=Mock(state={
|
|
||||||
'colormode': 'xy',
|
|
||||||
'hue': None,
|
|
||||||
'sat': 123,
|
|
||||||
'xy': [0.4, 0.5]
|
'xy': [0.4, 0.5]
|
||||||
}),
|
}),
|
||||||
request_bridge_update=None,
|
request_bridge_update=None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user