Fix color mode attribute for both official and non official Hue lights (#97683)
This commit is contained in:
parent
9b9b746138
commit
6ed31840bc
1 changed files with 16 additions and 4 deletions
|
@ -89,6 +89,7 @@ class HueLight(HueBaseEntity, LightEntity):
|
||||||
self._supported_color_modes.add(ColorMode.BRIGHTNESS)
|
self._supported_color_modes.add(ColorMode.BRIGHTNESS)
|
||||||
# support transition if brightness control
|
# support transition if brightness control
|
||||||
self._attr_supported_features |= LightEntityFeature.TRANSITION
|
self._attr_supported_features |= LightEntityFeature.TRANSITION
|
||||||
|
self._color_temp_active: bool = False
|
||||||
# get list of supported effects (combine effects and timed_effects)
|
# get list of supported effects (combine effects and timed_effects)
|
||||||
self._attr_effect_list = []
|
self._attr_effect_list = []
|
||||||
if effects := resource.effects:
|
if effects := resource.effects:
|
||||||
|
@ -121,9 +122,7 @@ class HueLight(HueBaseEntity, LightEntity):
|
||||||
@property
|
@property
|
||||||
def color_mode(self) -> ColorMode:
|
def color_mode(self) -> ColorMode:
|
||||||
"""Return the color mode of the light."""
|
"""Return the color mode of the light."""
|
||||||
if color_temp := self.resource.color_temperature:
|
if self.color_temp_active:
|
||||||
# Hue lights return `mired_valid` to indicate CT is active
|
|
||||||
if color_temp.mirek is not None:
|
|
||||||
return ColorMode.COLOR_TEMP
|
return ColorMode.COLOR_TEMP
|
||||||
if self.resource.supports_color:
|
if self.resource.supports_color:
|
||||||
return ColorMode.XY
|
return ColorMode.XY
|
||||||
|
@ -132,6 +131,18 @@ class HueLight(HueBaseEntity, LightEntity):
|
||||||
# fallback to on_off
|
# fallback to on_off
|
||||||
return ColorMode.ONOFF
|
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
|
@property
|
||||||
def xy_color(self) -> tuple[float, float] | None:
|
def xy_color(self) -> tuple[float, float] | None:
|
||||||
"""Return the xy color."""
|
"""Return the xy color."""
|
||||||
|
@ -193,6 +204,7 @@ class HueLight(HueBaseEntity, LightEntity):
|
||||||
xy_color = kwargs.get(ATTR_XY_COLOR)
|
xy_color = kwargs.get(ATTR_XY_COLOR)
|
||||||
color_temp = normalize_hue_colortemp(kwargs.get(ATTR_COLOR_TEMP))
|
color_temp = normalize_hue_colortemp(kwargs.get(ATTR_COLOR_TEMP))
|
||||||
brightness = normalize_hue_brightness(kwargs.get(ATTR_BRIGHTNESS))
|
brightness = normalize_hue_brightness(kwargs.get(ATTR_BRIGHTNESS))
|
||||||
|
self._color_temp_active = color_temp is not None
|
||||||
flash = kwargs.get(ATTR_FLASH)
|
flash = kwargs.get(ATTR_FLASH)
|
||||||
effect = effect_str = kwargs.get(ATTR_EFFECT)
|
effect = effect_str = kwargs.get(ATTR_EFFECT)
|
||||||
if effect_str in (EFFECT_NONE, EFFECT_NONE.lower()):
|
if effect_str in (EFFECT_NONE, EFFECT_NONE.lower()):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue