Skip to content

Commit

Permalink
Fix color mode attribute for both official and non official Hue lights (
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Aug 3, 2023
1 parent 9b9b746 commit 6ed3184
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions homeassistant/components/hue/v2/light.py
Expand Up @@ -89,6 +89,7 @@ def __init__(
self._supported_color_modes.add(ColorMode.BRIGHTNESS)
# support transition if brightness control
self._attr_supported_features |= LightEntityFeature.TRANSITION
self._color_temp_active: bool = False
# get list of supported effects (combine effects and timed_effects)
self._attr_effect_list = []
if effects := resource.effects:
Expand Down Expand Up @@ -121,17 +122,27 @@ def is_on(self) -> bool:
@property
def color_mode(self) -> ColorMode:
"""Return the color mode of the light."""
if color_temp := self.resource.color_temperature:
# Hue lights return `mired_valid` to indicate CT is active
if color_temp.mirek is not None:
return ColorMode.COLOR_TEMP
if self.color_temp_active:
return ColorMode.COLOR_TEMP
if self.resource.supports_color:
return ColorMode.XY
if self.resource.supports_dimming:
return ColorMode.BRIGHTNESS
# fallback to on_off
return ColorMode.ONOFF

@property
def color_temp_active(self) -> bool:
"""Return if the light is in Color Temperature mode."""
color_temp = self.resource.color_temperature
if color_temp is None or color_temp.mirek is None:
return False
# Official Hue lights return `mirek_valid` to indicate CT is active
# while non-official lights do not.
if self.device.product_data.certified:
return self.resource.color_temperature.mirek_valid
return self._color_temp_active

@property
def xy_color(self) -> tuple[float, float] | None:
"""Return the xy color."""
Expand Down Expand Up @@ -193,6 +204,7 @@ async def async_turn_on(self, **kwargs: Any) -> None:
xy_color = kwargs.get(ATTR_XY_COLOR)
color_temp = normalize_hue_colortemp(kwargs.get(ATTR_COLOR_TEMP))
brightness = normalize_hue_brightness(kwargs.get(ATTR_BRIGHTNESS))
self._color_temp_active = color_temp is not None
flash = kwargs.get(ATTR_FLASH)
effect = effect_str = kwargs.get(ATTR_EFFECT)
if effect_str in (EFFECT_NONE, EFFECT_NONE.lower()):
Expand Down

0 comments on commit 6ed3184

Please sign in to comment.