From 46e513615e3604970f11c7f5c81d84b94a02a855 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:25:25 +0100 Subject: [PATCH] Migrate switchbot lights to use Kelvin (#132695) --- homeassistant/components/switchbot/light.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/switchbot/light.py b/homeassistant/components/switchbot/light.py index 836ba1bd4f3..927ad5120c7 100644 --- a/homeassistant/components/switchbot/light.py +++ b/homeassistant/components/switchbot/light.py @@ -8,17 +8,13 @@ from switchbot import ColorMode as SwitchBotColorMode, SwitchbotBaseLight from homeassistant.components.light import ( ATTR_BRIGHTNESS, - ATTR_COLOR_TEMP, + ATTR_COLOR_TEMP_KELVIN, ATTR_RGB_COLOR, ColorMode, LightEntity, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.color import ( - color_temperature_kelvin_to_mired, - color_temperature_mired_to_kelvin, -) from .coordinator import SwitchbotConfigEntry, SwitchbotDataUpdateCoordinator from .entity import SwitchbotEntity @@ -50,8 +46,8 @@ class SwitchbotLightEntity(SwitchbotEntity, LightEntity): """Initialize the Switchbot light.""" super().__init__(coordinator) device = self._device - self._attr_min_mireds = color_temperature_kelvin_to_mired(device.max_temp) - self._attr_max_mireds = color_temperature_kelvin_to_mired(device.min_temp) + self._attr_max_color_temp_kelvin = device.max_temp + self._attr_min_color_temp_kelvin = device.min_temp self._attr_supported_color_modes = { SWITCHBOT_COLOR_MODE_TO_HASS[mode] for mode in device.color_modes } @@ -64,7 +60,7 @@ class SwitchbotLightEntity(SwitchbotEntity, LightEntity): self._attr_is_on = self._device.on self._attr_brightness = max(0, min(255, round(device.brightness * 2.55))) if device.color_mode == SwitchBotColorMode.COLOR_TEMP: - self._attr_color_temp = color_temperature_kelvin_to_mired(device.color_temp) + self._attr_color_temp_kelvin = device.color_temp self._attr_color_mode = ColorMode.COLOR_TEMP return self._attr_rgb_color = device.rgb @@ -77,10 +73,9 @@ class SwitchbotLightEntity(SwitchbotEntity, LightEntity): if ( self.supported_color_modes and ColorMode.COLOR_TEMP in self.supported_color_modes - and ATTR_COLOR_TEMP in kwargs + and ATTR_COLOR_TEMP_KELVIN in kwargs ): - color_temp = kwargs[ATTR_COLOR_TEMP] - kelvin = max(2700, min(6500, color_temperature_mired_to_kelvin(color_temp))) + kelvin = max(2700, min(6500, kwargs[ATTR_COLOR_TEMP_KELVIN])) await self._device.set_color_temp(brightness, kelvin) return if ATTR_RGB_COLOR in kwargs: