mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Migrate deconz lights to use Kelvin (#132698)
* Use ATTR_COLOR_TEMP_KELVIN in kelvin light * Adjust
This commit is contained in:
parent
e4ba94f939
commit
b139af9a9c
@ -12,7 +12,7 @@ from pydeconz.models.light.light import Light, LightAlert, LightColorMode, Light
|
|||||||
|
|
||||||
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_FLASH,
|
ATTR_FLASH,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
@ -30,7 +30,11 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.color import color_hs_to_xy
|
from homeassistant.util.color import (
|
||||||
|
color_hs_to_xy,
|
||||||
|
color_temperature_kelvin_to_mired,
|
||||||
|
color_temperature_mired_to_kelvin,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS
|
from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS
|
||||||
from .entity import DeconzDevice
|
from .entity import DeconzDevice
|
||||||
@ -256,9 +260,11 @@ class DeconzBaseLight[_LightDeviceT: Group | Light](
|
|||||||
return self._device.brightness
|
return self._device.brightness
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self) -> int | None:
|
def color_temp_kelvin(self) -> int | None:
|
||||||
"""Return the CT color value."""
|
"""Return the CT color value."""
|
||||||
return self._device.color_temp
|
if self._device.color_temp is None:
|
||||||
|
return None
|
||||||
|
return color_temperature_mired_to_kelvin(self._device.color_temp)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hs_color(self) -> tuple[float, float] | None:
|
def hs_color(self) -> tuple[float, float] | None:
|
||||||
@ -284,8 +290,10 @@ class DeconzBaseLight[_LightDeviceT: Group | Light](
|
|||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
data["brightness"] = kwargs[ATTR_BRIGHTNESS]
|
data["brightness"] = kwargs[ATTR_BRIGHTNESS]
|
||||||
|
|
||||||
if ATTR_COLOR_TEMP in kwargs:
|
if ATTR_COLOR_TEMP_KELVIN in kwargs:
|
||||||
data["color_temperature"] = kwargs[ATTR_COLOR_TEMP]
|
data["color_temperature"] = color_temperature_kelvin_to_mired(
|
||||||
|
kwargs[ATTR_COLOR_TEMP_KELVIN]
|
||||||
|
)
|
||||||
|
|
||||||
if ATTR_HS_COLOR in kwargs:
|
if ATTR_HS_COLOR in kwargs:
|
||||||
if ColorMode.XY in self._attr_supported_color_modes:
|
if ColorMode.XY in self._attr_supported_color_modes:
|
||||||
@ -338,14 +346,18 @@ class DeconzLight(DeconzBaseLight[Light]):
|
|||||||
"""Representation of a deCONZ light."""
|
"""Representation of a deCONZ light."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_mireds(self) -> int:
|
def min_color_temp_kelvin(self) -> int:
|
||||||
"""Return the warmest color_temp that this light supports."""
|
"""Return the warmest color_temp_kelvin that this light supports."""
|
||||||
return self._device.max_color_temp or super().max_mireds
|
if max_color_temp_mireds := self._device.max_color_temp:
|
||||||
|
return color_temperature_mired_to_kelvin(max_color_temp_mireds)
|
||||||
|
return super().min_color_temp_kelvin
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_mireds(self) -> int:
|
def max_color_temp_kelvin(self) -> int:
|
||||||
"""Return the coldest color_temp that this light supports."""
|
"""Return the coldest color_temp_kelvin that this light supports."""
|
||||||
return self._device.min_color_temp or super().min_mireds
|
if min_color_temp_mireds := self._device.min_color_temp:
|
||||||
|
return color_temperature_mired_to_kelvin(min_color_temp_mireds)
|
||||||
|
return super().max_color_temp_kelvin
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_callback(self) -> None:
|
def async_update_callback(self) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user