Fix color mode attribute for both official and non official Hue lights (#97683)

pull/97772/head
Marcel van der Veldt 2023-08-03 21:06:45 +02:00 committed by Franck Nijhof
parent 0a24299e23
commit 12d3bce3a7
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
1 changed files with 16 additions and 4 deletions

View File

@ -89,6 +89,7 @@ class HueLight(HueBaseEntity, LightEntity):
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:
@ -121,10 +122,8 @@ class HueLight(HueBaseEntity, LightEntity):
@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:
@ -132,6 +131,18 @@ class HueLight(HueBaseEntity, LightEntity):
# 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."""
@ -193,6 +204,7 @@ class HueLight(HueBaseEntity, LightEntity):
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()):