Migrate limitlessled light to color_mode (#69430)

This commit is contained in:
Erik Montnemery 2022-05-13 11:40:22 +02:00 committed by GitHub
parent d3c25bf450
commit 3adaad7381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,9 +24,7 @@ from homeassistant.components.light import (
EFFECT_WHITE, EFFECT_WHITE,
FLASH_LONG, FLASH_LONG,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS, ColorMode,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
LightEntity, LightEntity,
LightEntityFeature, LightEntityFeature,
) )
@ -60,27 +58,17 @@ MIN_SATURATION = 10
WHITE = [0, 0] WHITE = [0, 0]
SUPPORT_LIMITLESSLED_WHITE = ( COLOR_MODES_LIMITLESS_WHITE = {ColorMode.COLOR_TEMP}
SUPPORT_BRIGHTNESS SUPPORT_LIMITLESSLED_WHITE = LightEntityFeature.EFFECT | LightEntityFeature.TRANSITION
| SUPPORT_COLOR_TEMP COLOR_MODES_LIMITLESS_DIMMER = {ColorMode.BRIGHTNESS}
| LightEntityFeature.EFFECT SUPPORT_LIMITLESSLED_DIMMER = LightEntityFeature.TRANSITION
| LightEntityFeature.TRANSITION COLOR_MODES_LIMITLESS_RGB = {ColorMode.HS}
)
SUPPORT_LIMITLESSLED_DIMMER = SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION
SUPPORT_LIMITLESSLED_RGB = ( SUPPORT_LIMITLESSLED_RGB = (
SUPPORT_BRIGHTNESS LightEntityFeature.EFFECT | LightEntityFeature.FLASH | LightEntityFeature.TRANSITION
| LightEntityFeature.EFFECT
| LightEntityFeature.FLASH
| SUPPORT_COLOR
| LightEntityFeature.TRANSITION
) )
COLOR_MODES_LIMITLESS_RGBWW = {ColorMode.COLOR_TEMP, ColorMode.HS}
SUPPORT_LIMITLESSLED_RGBWW = ( SUPPORT_LIMITLESSLED_RGBWW = (
SUPPORT_BRIGHTNESS LightEntityFeature.EFFECT | LightEntityFeature.FLASH | LightEntityFeature.TRANSITION
| SUPPORT_COLOR_TEMP
| LightEntityFeature.EFFECT
| LightEntityFeature.FLASH
| SUPPORT_COLOR
| LightEntityFeature.TRANSITION
) )
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
@ -219,18 +207,31 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
"""Initialize a group.""" """Initialize a group."""
if isinstance(group, WhiteGroup): if isinstance(group, WhiteGroup):
self._supported = SUPPORT_LIMITLESSLED_WHITE self._attr_supported_color_modes = COLOR_MODES_LIMITLESS_WHITE
self._attr_supported_features = SUPPORT_LIMITLESSLED_WHITE
self._effect_list = [EFFECT_NIGHT] self._effect_list = [EFFECT_NIGHT]
elif isinstance(group, DimmerGroup): elif isinstance(group, DimmerGroup):
self._supported = SUPPORT_LIMITLESSLED_DIMMER self._attr_supported_color_modes = COLOR_MODES_LIMITLESS_DIMMER
self._attr_supported_features = SUPPORT_LIMITLESSLED_DIMMER
self._effect_list = [] self._effect_list = []
elif isinstance(group, RgbwGroup): elif isinstance(group, RgbwGroup):
self._supported = SUPPORT_LIMITLESSLED_RGB self._attr_supported_color_modes = COLOR_MODES_LIMITLESS_RGB
self._attr_supported_features = SUPPORT_LIMITLESSLED_RGB
self._effect_list = [EFFECT_COLORLOOP, EFFECT_NIGHT, EFFECT_WHITE] self._effect_list = [EFFECT_COLORLOOP, EFFECT_NIGHT, EFFECT_WHITE]
elif isinstance(group, RgbwwGroup): elif isinstance(group, RgbwwGroup):
self._supported = SUPPORT_LIMITLESSLED_RGBWW self._attr_supported_color_modes = COLOR_MODES_LIMITLESS_RGBWW
self._attr_supported_features = SUPPORT_LIMITLESSLED_RGBWW
self._effect_list = [EFFECT_COLORLOOP, EFFECT_NIGHT, EFFECT_WHITE] self._effect_list = [EFFECT_COLORLOOP, EFFECT_NIGHT, EFFECT_WHITE]
self._fixed_color_mode = None
if len(self._attr_supported_color_modes) == 1:
self._fixed_color_mode = next(iter(self._attr_supported_color_modes))
else:
assert self._attr_supported_color_modes == {
ColorMode.COLOR_TEMP,
ColorMode.HS,
}
self.group = group self.group = group
self.config = config self.config = config
self._is_on = False self._is_on = False
@ -286,29 +287,27 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
"""Return the warmest color_temp that this light supports.""" """Return the warmest color_temp that this light supports."""
return 370 return 370
@property
def color_mode(self) -> str | None:
"""Return the color mode of the light."""
if self._fixed_color_mode:
return self._fixed_color_mode
# The light supports both hs and white with adjustable color temperature
if self._effect == EFFECT_NIGHT or self._color is None or self._color[1] == 0:
return ColorMode.COLOR_TEMP
return ColorMode.HS
@property @property
def color_temp(self): def color_temp(self):
"""Return the temperature property.""" """Return the temperature property."""
if self.hs_color is not None:
return None
return self._temperature return self._temperature
@property @property
def hs_color(self): def hs_color(self):
"""Return the color property.""" """Return the color property."""
if self._effect == EFFECT_NIGHT:
return None
if self._color is None or self._color[1] == 0:
return None
return self._color return self._color
@property
def supported_features(self):
"""Flag supported features."""
return self._supported
@property @property
def effect(self): def effect(self):
"""Return the current effect for this light.""" """Return the current effect for this light."""
@ -349,7 +348,7 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
self._brightness = kwargs[ATTR_BRIGHTNESS] self._brightness = kwargs[ATTR_BRIGHTNESS]
args["brightness"] = self.limitlessled_brightness() args["brightness"] = self.limitlessled_brightness()
if ATTR_HS_COLOR in kwargs and self._supported & SUPPORT_COLOR: if ATTR_HS_COLOR in kwargs:
self._color = kwargs[ATTR_HS_COLOR] self._color = kwargs[ATTR_HS_COLOR]
# White is a special case. # White is a special case.
if self._color[1] < MIN_SATURATION: if self._color[1] < MIN_SATURATION:
@ -359,18 +358,17 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
args["color"] = self.limitlessled_color() args["color"] = self.limitlessled_color()
if ATTR_COLOR_TEMP in kwargs: if ATTR_COLOR_TEMP in kwargs:
if self._supported & SUPPORT_COLOR: if ColorMode.HS in self.supported_color_modes:
pipeline.white() pipeline.white()
self._color = WHITE self._color = WHITE
if self._supported & SUPPORT_COLOR_TEMP: self._temperature = kwargs[ATTR_COLOR_TEMP]
self._temperature = kwargs[ATTR_COLOR_TEMP] args["temperature"] = self.limitlessled_temperature()
args["temperature"] = self.limitlessled_temperature()
if args: if args:
pipeline.transition(transition_time, **args) pipeline.transition(transition_time, **args)
# Flash. # Flash.
if ATTR_FLASH in kwargs and self._supported & LightEntityFeature.FLASH: if ATTR_FLASH in kwargs and self.supported_features & LightEntityFeature.FLASH:
duration = 0 duration = 0
if kwargs[ATTR_FLASH] == FLASH_LONG: if kwargs[ATTR_FLASH] == FLASH_LONG:
duration = 1 duration = 1