Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions homeassistant/components/hue/v2/light.py
Expand Up @@ -89,6 +89,7 @@
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 @@
@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

Check warning on line 144 in homeassistant/components/hue/v2/light.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/hue/v2/light.py#L144

Added line #L144 was not covered by tests

@property
def xy_color(self) -> tuple[float, float] | None:
"""Return the xy color."""
Expand Down Expand Up @@ -193,6 +204,7 @@
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