Skip to content
Merged
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
86 changes: 42 additions & 44 deletions homeassistant/components/limitlessled/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
EFFECT_WHITE,
FLASH_LONG,
PLATFORM_SCHEMA,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
ColorMode,
LightEntity,
LightEntityFeature,
)
Expand Down Expand Up @@ -60,27 +58,17 @@

WHITE = [0, 0]

SUPPORT_LIMITLESSLED_WHITE = (
SUPPORT_BRIGHTNESS
| SUPPORT_COLOR_TEMP
| LightEntityFeature.EFFECT
| LightEntityFeature.TRANSITION
)
SUPPORT_LIMITLESSLED_DIMMER = SUPPORT_BRIGHTNESS | LightEntityFeature.TRANSITION
COLOR_MODES_LIMITLESS_WHITE = {ColorMode.COLOR_TEMP}
SUPPORT_LIMITLESSLED_WHITE = LightEntityFeature.EFFECT | LightEntityFeature.TRANSITION
COLOR_MODES_LIMITLESS_DIMMER = {ColorMode.BRIGHTNESS}
SUPPORT_LIMITLESSLED_DIMMER = LightEntityFeature.TRANSITION
COLOR_MODES_LIMITLESS_RGB = {ColorMode.HS}
SUPPORT_LIMITLESSLED_RGB = (
SUPPORT_BRIGHTNESS
| LightEntityFeature.EFFECT
| LightEntityFeature.FLASH
| SUPPORT_COLOR
| LightEntityFeature.TRANSITION
LightEntityFeature.EFFECT | LightEntityFeature.FLASH | LightEntityFeature.TRANSITION
)
COLOR_MODES_LIMITLESS_RGBWW = {ColorMode.COLOR_TEMP, ColorMode.HS}
SUPPORT_LIMITLESSLED_RGBWW = (
SUPPORT_BRIGHTNESS
| SUPPORT_COLOR_TEMP
| LightEntityFeature.EFFECT
| LightEntityFeature.FLASH
| SUPPORT_COLOR
| LightEntityFeature.TRANSITION
LightEntityFeature.EFFECT | LightEntityFeature.FLASH | LightEntityFeature.TRANSITION
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
Expand Down Expand Up @@ -219,18 +207,31 @@ def __init__(self, group, config):
"""Initialize a group."""

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]
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 = []
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]
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._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.config = config
self._is_on = False
Expand Down Expand Up @@ -286,29 +287,27 @@ def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
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:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copying the condition from the hs_color attribute, which was previously gated by checking if the saturation was 0. @smwa can you help confirm that's the correct way to determine the current mode of the light (color or white with adjustable color temperature)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Affirmative, this should be sufficient

return ColorMode.COLOR_TEMP
return ColorMode.HS

@property
def color_temp(self):
"""Return the temperature property."""
if self.hs_color is not None:
return None
return self._temperature

@property
def hs_color(self):
"""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

@property
def supported_features(self):
"""Flag supported features."""
return self._supported

@property
def effect(self):
"""Return the current effect for this light."""
Expand Down Expand Up @@ -349,7 +348,7 @@ def turn_on(self, transition_time, pipeline, **kwargs):
self._brightness = kwargs[ATTR_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]
# White is a special case.
if self._color[1] < MIN_SATURATION:
Expand All @@ -359,18 +358,17 @@ def turn_on(self, transition_time, pipeline, **kwargs):
args["color"] = self.limitlessled_color()

if ATTR_COLOR_TEMP in kwargs:
if self._supported & SUPPORT_COLOR:
if ColorMode.HS in self.supported_color_modes:
pipeline.white()
self._color = WHITE
if self._supported & SUPPORT_COLOR_TEMP:
self._temperature = kwargs[ATTR_COLOR_TEMP]
args["temperature"] = self.limitlessled_temperature()
self._temperature = kwargs[ATTR_COLOR_TEMP]
args["temperature"] = self.limitlessled_temperature()

if args:
pipeline.transition(transition_time, **args)

# Flash.
if ATTR_FLASH in kwargs and self._supported & LightEntityFeature.FLASH:
if ATTR_FLASH in kwargs and self.supported_features & LightEntityFeature.FLASH:
duration = 0
if kwargs[ATTR_FLASH] == FLASH_LONG:
duration = 1
Expand Down