From 033f3907338691c1bc8f39a6a09646de9e97f1ea Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:58:48 +0000 Subject: [PATCH 1/2] Use ATTR_COLOR_TEMP_KELVIN in kelvin light --- homeassistant/components/deconz/light.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index 95a97959d5b93..7123b390f756c 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -12,7 +12,7 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS, - ATTR_COLOR_TEMP, + ATTR_COLOR_TEMP_KELVIN, ATTR_EFFECT, ATTR_FLASH, ATTR_HS_COLOR, @@ -30,7 +30,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceInfo 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 from .const import DOMAIN as DECONZ_DOMAIN, POWER_PLUGS from .entity import DeconzDevice @@ -284,8 +284,10 @@ async def async_turn_on(self, **kwargs: Any) -> None: if ATTR_BRIGHTNESS in kwargs: data["brightness"] = kwargs[ATTR_BRIGHTNESS] - if ATTR_COLOR_TEMP in kwargs: - data["color_temperature"] = kwargs[ATTR_COLOR_TEMP] + if ATTR_COLOR_TEMP_KELVIN in kwargs: + data["color_temperature"] = color_temperature_kelvin_to_mired( + kwargs[ATTR_COLOR_TEMP_KELVIN] + ) if ATTR_HS_COLOR in kwargs: if ColorMode.XY in self._attr_supported_color_modes: From 5109309b15e459af9e81674ae7fb023f56d06d4a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:42:02 +0000 Subject: [PATCH 2/2] Adjust --- homeassistant/components/deconz/light.py | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index 7123b390f756c..acfbff98297e1 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -30,7 +30,11 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.color import color_hs_to_xy, color_temperature_kelvin_to_mired +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 .entity import DeconzDevice @@ -256,9 +260,11 @@ def brightness(self) -> int | None: return self._device.brightness @property - def color_temp(self) -> int | None: + def color_temp_kelvin(self) -> int | None: """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 def hs_color(self) -> tuple[float, float] | None: @@ -340,14 +346,18 @@ class DeconzLight(DeconzBaseLight[Light]): """Representation of a deCONZ light.""" @property - def max_mireds(self) -> int: - """Return the warmest color_temp that this light supports.""" - return self._device.max_color_temp or super().max_mireds + def min_color_temp_kelvin(self) -> int: + """Return the warmest color_temp_kelvin that this light supports.""" + 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 - def min_mireds(self) -> int: - """Return the coldest color_temp that this light supports.""" - return self._device.min_color_temp or super().min_mireds + def max_color_temp_kelvin(self) -> int: + """Return the coldest color_temp_kelvin that this light supports.""" + 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 def async_update_callback(self) -> None: