Use ColorMode enum in hue (#70578)
parent
8330d7906a
commit
965665213f
|
@ -14,13 +14,10 @@ from homeassistant.components.light import (
|
|||
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
|
||||
|
@ -204,7 +201,7 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
|
|||
@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
|
||||
|
@ -241,18 +238,18 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
|
|||
# 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
|
||||
|
@ -260,10 +257,10 @@ class GroupedHueLight(HueBaseEntity, LightEntity):
|
|||
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
|
||||
|
|
|
@ -16,14 +16,11 @@ from homeassistant.components.light import (
|
|||
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
|
||||
|
@ -80,15 +77,15 @@ class HueLight(HueBaseEntity, LightEntity):
|
|||
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)
|
||||
|
@ -121,18 +118,18 @@ class HueLight(HueBaseEntity, LightEntity):
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue