Migrate flux_led lights to use Kelvin (#132687)

pull/132627/merge
epenet 2024-12-09 16:25:15 +01:00 committed by GitHub
parent 21a2ce6b59
commit a20347963e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 13 deletions

View File

@ -14,7 +14,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
@ -30,10 +30,6 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import VolDictType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.color import (
color_temperature_kelvin_to_mired,
color_temperature_mired_to_kelvin,
)
from .const import (
CONF_COLORS,
@ -67,7 +63,7 @@ _LOGGER = logging.getLogger(__name__)
MODE_ATTRS = {
ATTR_EFFECT,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
ATTR_RGBWW_COLOR,
@ -205,8 +201,8 @@ class FluxLight(
) -> None:
"""Initialize the light."""
super().__init__(coordinator, base_unique_id, None)
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_min_color_temp_kelvin = self._device.min_temp
self._attr_max_color_temp_kelvin = self._device.max_temp
self._attr_supported_color_modes = _hass_color_modes(self._device)
custom_effects: list[str] = []
if custom_effect_colors:
@ -222,9 +218,9 @@ class FluxLight(
return self._device.brightness
@property
def color_temp(self) -> int:
"""Return the kelvin value of this light in mired."""
return color_temperature_kelvin_to_mired(self._device.color_temp)
def color_temp_kelvin(self) -> int:
"""Return the kelvin value of this light."""
return self._device.color_temp
@property
def rgb_color(self) -> tuple[int, int, int]:
@ -304,8 +300,7 @@ class FluxLight(
await self._async_set_effect(effect, brightness)
return
# 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 color_temp_kelvin := kwargs.get(ATTR_COLOR_TEMP_KELVIN):
if (
ATTR_BRIGHTNESS not in kwargs
and self.color_mode in MULTI_BRIGHTNESS_COLOR_MODES