mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Migrate flux_led lights to use Kelvin (#132687)
This commit is contained in:
parent
21a2ce6b59
commit
a20347963e
@ -14,7 +14,7 @@ import voluptuous as vol
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_RGBW_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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import VolDictType
|
from homeassistant.helpers.typing import VolDictType
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
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 (
|
from .const import (
|
||||||
CONF_COLORS,
|
CONF_COLORS,
|
||||||
@ -67,7 +63,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
MODE_ATTRS = {
|
MODE_ATTRS = {
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_RGBW_COLOR,
|
ATTR_RGBW_COLOR,
|
||||||
ATTR_RGBWW_COLOR,
|
ATTR_RGBWW_COLOR,
|
||||||
@ -205,8 +201,8 @@ class FluxLight(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
super().__init__(coordinator, base_unique_id, None)
|
super().__init__(coordinator, base_unique_id, None)
|
||||||
self._attr_min_mireds = color_temperature_kelvin_to_mired(self._device.max_temp)
|
self._attr_min_color_temp_kelvin = self._device.min_temp
|
||||||
self._attr_max_mireds = color_temperature_kelvin_to_mired(self._device.min_temp)
|
self._attr_max_color_temp_kelvin = self._device.max_temp
|
||||||
self._attr_supported_color_modes = _hass_color_modes(self._device)
|
self._attr_supported_color_modes = _hass_color_modes(self._device)
|
||||||
custom_effects: list[str] = []
|
custom_effects: list[str] = []
|
||||||
if custom_effect_colors:
|
if custom_effect_colors:
|
||||||
@ -222,9 +218,9 @@ class FluxLight(
|
|||||||
return self._device.brightness
|
return self._device.brightness
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self) -> int:
|
def color_temp_kelvin(self) -> int:
|
||||||
"""Return the kelvin value of this light in mired."""
|
"""Return the kelvin value of this light."""
|
||||||
return color_temperature_kelvin_to_mired(self._device.color_temp)
|
return self._device.color_temp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rgb_color(self) -> tuple[int, int, int]:
|
def rgb_color(self) -> tuple[int, int, int]:
|
||||||
@ -304,8 +300,7 @@ class FluxLight(
|
|||||||
await self._async_set_effect(effect, brightness)
|
await self._async_set_effect(effect, brightness)
|
||||||
return
|
return
|
||||||
# Handle switch to CCT Color Mode
|
# Handle switch to CCT Color Mode
|
||||||
if color_temp_mired := kwargs.get(ATTR_COLOR_TEMP):
|
if color_temp_kelvin := kwargs.get(ATTR_COLOR_TEMP_KELVIN):
|
||||||
color_temp_kelvin = color_temperature_mired_to_kelvin(color_temp_mired)
|
|
||||||
if (
|
if (
|
||||||
ATTR_BRIGHTNESS not in kwargs
|
ATTR_BRIGHTNESS not in kwargs
|
||||||
and self.color_mode in MULTI_BRIGHTNESS_COLOR_MODES
|
and self.color_mode in MULTI_BRIGHTNESS_COLOR_MODES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user