Add support for changing the white strip type to flux_led (#63943)
This commit is contained in:
parent
5622db10b1
commit
1c6ca908d1
11 changed files with 304 additions and 54 deletions
|
@ -7,12 +7,7 @@ from typing import Any, Final
|
|||
|
||||
from flux_led.const import MultiColorEffects
|
||||
from flux_led.protocol import MusicMode
|
||||
from flux_led.utils import (
|
||||
color_temp_to_white_levels,
|
||||
rgbcw_brightness,
|
||||
rgbcw_to_rgbwc,
|
||||
rgbw_brightness,
|
||||
)
|
||||
from flux_led.utils import rgbcw_brightness, rgbcw_to_rgbwc, rgbw_brightness
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -24,7 +19,6 @@ from homeassistant.components.light import (
|
|||
ATTR_RGBW_COLOR,
|
||||
ATTR_RGBWW_COLOR,
|
||||
ATTR_WHITE,
|
||||
COLOR_MODE_RGBWW,
|
||||
SUPPORT_EFFECT,
|
||||
SUPPORT_TRANSITION,
|
||||
LightEntity,
|
||||
|
@ -50,6 +44,7 @@ from .const import (
|
|||
CONF_TRANSITION,
|
||||
DEFAULT_EFFECT_SPEED,
|
||||
DOMAIN,
|
||||
MULTI_BRIGHTNESS_COLOR_MODES,
|
||||
TRANSITION_GRADUAL,
|
||||
TRANSITION_JUMP,
|
||||
TRANSITION_STROBE,
|
||||
|
@ -203,9 +198,7 @@ class FluxLight(FluxOnOffEntity, CoordinatorEntity, LightEntity):
|
|||
) -> None:
|
||||
"""Initialize the light."""
|
||||
super().__init__(coordinator, unique_id, name, None)
|
||||
self._attr_min_mireds = (
|
||||
color_temperature_kelvin_to_mired(self._device.max_temp) + 1
|
||||
) # for rounding
|
||||
self._attr_min_mireds = color_temperature_kelvin_to_mired(self._device.max_temp)
|
||||
self._attr_max_mireds = color_temperature_kelvin_to_mired(self._device.min_temp)
|
||||
self._attr_supported_color_modes = _hass_color_modes(self._device)
|
||||
custom_effects: list[str] = []
|
||||
|
@ -306,20 +299,14 @@ class FluxLight(FluxOnOffEntity, CoordinatorEntity, LightEntity):
|
|||
# Handle switch to CCT Color Mode
|
||||
if color_temp_mired := kwargs.get(ATTR_COLOR_TEMP):
|
||||
color_temp_kelvin = color_temperature_mired_to_kelvin(color_temp_mired)
|
||||
if self.color_mode != COLOR_MODE_RGBWW:
|
||||
await self._device.async_set_white_temp(color_temp_kelvin, brightness)
|
||||
return
|
||||
|
||||
# When switching to color temp from RGBWW mode,
|
||||
# we do not want the overall brightness, we only
|
||||
# want the brightness of the white channels
|
||||
brightness = kwargs.get(
|
||||
ATTR_BRIGHTNESS, self._device.getWhiteTemperature()[1]
|
||||
)
|
||||
channels = color_temp_to_white_levels(color_temp_kelvin, brightness)
|
||||
warm = channels.warm_white
|
||||
cold = channels.cool_white
|
||||
await self._device.async_set_levels(r=0, b=0, g=0, w=warm, w2=cold)
|
||||
if (
|
||||
ATTR_BRIGHTNESS not in kwargs
|
||||
and self.color_mode in MULTI_BRIGHTNESS_COLOR_MODES
|
||||
):
|
||||
# When switching to color temp from RGBWW or RGB&W mode,
|
||||
# we do not want the overall brightness of the RGB channels
|
||||
brightness = max(self._device.rgb)
|
||||
await self._device.async_set_white_temp(color_temp_kelvin, brightness)
|
||||
return
|
||||
# Handle switch to RGB Color Mode
|
||||
if rgb := kwargs.get(ATTR_RGB_COLOR):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue