Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions homeassistant/components/hue/v2/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
ATTR_FLASH,
ATTR_TRANSITION,
ATTR_XY_COLOR,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_ONOFF,
COLOR_MODE_XY,
FLASH_SHORT,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
ColorMode,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -204,7 +201,7 @@ def on_update(self) -> None:
@callback
def _update_values(self) -> None:
"""Set base values from underlying lights of a group."""
supported_color_modes = set()
supported_color_modes: set[ColorMode | str] = set()
lights_with_color_support = 0
lights_with_color_temp_support = 0
lights_with_dimming_support = 0
Expand Down Expand Up @@ -241,29 +238,29 @@ def _update_values(self) -> None:
# this means that the state is derived from only some of the lights
# and will never be 100% accurate but it will be close
if lights_with_color_support > 0:
supported_color_modes.add(COLOR_MODE_XY)
supported_color_modes.add(ColorMode.XY)
if lights_with_color_temp_support > 0:
supported_color_modes.add(COLOR_MODE_COLOR_TEMP)
supported_color_modes.add(ColorMode.COLOR_TEMP)
if lights_with_dimming_support > 0:
if len(supported_color_modes) == 0:
# only add color mode brightness if no color variants
supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
supported_color_modes.add(ColorMode.BRIGHTNESS)
self._attr_brightness = round(
((total_brightness / lights_with_dimming_support) / 100) * 255
)
else:
supported_color_modes.add(COLOR_MODE_ONOFF)
supported_color_modes.add(ColorMode.ONOFF)
self._dynamic_mode_active = lights_in_dynamic_mode > 0
self._attr_supported_color_modes = supported_color_modes
# pick a winner for the current colormode
if (
lights_with_color_temp_support > 0
and lights_in_colortemp_mode == lights_with_color_temp_support
):
self._attr_color_mode = COLOR_MODE_COLOR_TEMP
self._attr_color_mode = ColorMode.COLOR_TEMP
elif lights_with_color_support > 0:
self._attr_color_mode = COLOR_MODE_XY
self._attr_color_mode = ColorMode.XY
elif lights_with_dimming_support > 0:
self._attr_color_mode = COLOR_MODE_BRIGHTNESS
self._attr_color_mode = ColorMode.BRIGHTNESS
else:
self._attr_color_mode = COLOR_MODE_ONOFF
self._attr_color_mode = ColorMode.ONOFF
23 changes: 10 additions & 13 deletions homeassistant/components/hue/v2/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
ATTR_FLASH,
ATTR_TRANSITION,
ATTR_XY_COLOR,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_ONOFF,
COLOR_MODE_XY,
FLASH_SHORT,
SUPPORT_EFFECT,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
ColorMode,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -80,15 +77,15 @@ def __init__(
self._attr_supported_features |= SUPPORT_FLASH
self.resource = resource
self.controller = controller
self._supported_color_modes = set()
self._supported_color_modes: set[ColorMode | str] = set()
if self.resource.supports_color:
self._supported_color_modes.add(COLOR_MODE_XY)
self._supported_color_modes.add(ColorMode.XY)
if self.resource.supports_color_temperature:
self._supported_color_modes.add(COLOR_MODE_COLOR_TEMP)
self._supported_color_modes.add(ColorMode.COLOR_TEMP)
if self.resource.supports_dimming:
if len(self._supported_color_modes) == 0:
# only add color mode brightness if no color variants
self._supported_color_modes.add(COLOR_MODE_BRIGHTNESS)
self._supported_color_modes.add(ColorMode.BRIGHTNESS)
# support transition if brightness control
self._attr_supported_features |= SUPPORT_TRANSITION
# get list of supported effects (combine effects and timed_effects)
Expand Down Expand Up @@ -121,18 +118,18 @@ def is_on(self) -> bool:
return self.resource.on.on

@property
def color_mode(self) -> str | None:
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_valid and color_temp.mirek is not None:
return COLOR_MODE_COLOR_TEMP
return ColorMode.COLOR_TEMP
if self.resource.supports_color:
return COLOR_MODE_XY
return ColorMode.XY
if self.resource.supports_dimming:
return COLOR_MODE_BRIGHTNESS
return ColorMode.BRIGHTNESS
# fallback to on_off
return COLOR_MODE_ONOFF
return ColorMode.ONOFF

@property
def xy_color(self) -> tuple[float, float] | None:
Expand Down