Improve precision of Hue color state (#14113)
This commit is contained in:
parent
9d1f9fe204
commit
0b350993b5
2 changed files with 7 additions and 30 deletions
|
@ -242,27 +242,17 @@ class HueLight(Light):
|
|||
@property
|
||||
def hs_color(self):
|
||||
"""Return the hs color value."""
|
||||
# pylint: disable=redefined-outer-name
|
||||
mode = self._color_mode
|
||||
|
||||
if mode not in ('hs', 'xy'):
|
||||
return
|
||||
|
||||
source = self.light.action if self.is_group else self.light.state
|
||||
|
||||
hue = source.get('hue')
|
||||
sat = source.get('sat')
|
||||
|
||||
# Sometimes the state will not include valid hue/sat values.
|
||||
# Reported as issue 13434
|
||||
if hue is not None and sat is not None:
|
||||
return hue / 65535 * 360, sat / 255 * 100
|
||||
|
||||
if 'xy' not in source:
|
||||
return None
|
||||
|
||||
if mode == 'xy' and 'xy' in source:
|
||||
return color.color_xy_to_hs(*source['xy'])
|
||||
|
||||
if mode == 'hs' and 'hue' in source and 'sat' in source:
|
||||
return source['hue'] / 65535 * 360, source['sat'] / 255 * 100
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
"""Return the CT color value."""
|
||||
|
|
|
@ -237,7 +237,7 @@ 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['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')
|
||||
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.state == 'on'
|
||||
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
|
||||
|
||||
new_light1_on = LIGHT_1_ON.copy()
|
||||
|
@ -668,19 +668,6 @@ def test_hs_color():
|
|||
'colormode': 'xy',
|
||||
'hue': 1234,
|
||||
'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]
|
||||
}),
|
||||
request_bridge_update=None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue