Hue: Convert XY to HS color if HS not present (#13465)
* Hue: Convert XY to HS color if HS not present * Revert change to test * Address comments * Lint
This commit is contained in:
1 parent
263dbe5d81
commit
24e0bb198a
2 files changed
+76
-11
No files matched your search
@@ -18,6 +18,7 @@ from homeassistant.components.light import (
|
||||
FLASH_LONG, FLASH_SHORT, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP,
|
||||
SUPPORT_EFFECT, SUPPORT_FLASH, SUPPORT_COLOR, SUPPORT_TRANSITION,
|
||||
Light)
|
||||
from homeassistant.util import color
|
||||
|
||||
DEPENDENCIES = ['hue']
|
||||
SCAN_INTERVAL = timedelta(seconds=5)
|
||||
@@ -235,19 +236,26 @@ class HueLight(Light):
|
||||
@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":
|
||||
# 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 self.is_group:
|
||||
return (
|
||||
self.light.action.get('hue') / 65535 * 360,
|
||||
self.light.action.get('sat') / 255 * 100,
|
||||
)
|
||||
return (
|
||||
self.light.state.get('hue') / 65535 * 360,
|
||||
self.light.state.get('sat') / 255 * 100,
|
||||
)
|
||||
return color.color_xy_to_hs(*source['xy'])
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
|
||||
Reference in new issue
Block a user