From a11bf5cce11e17e94f3ac30c80df1175b06fcf5a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 10 Dec 2024 08:43:07 +0100 Subject: [PATCH] Migrate blebox lights to use Kelvin (#132787) --- homeassistant/components/blebox/light.py | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/blebox/light.py b/homeassistant/components/blebox/light.py index 33fff1d71da..c3c9de8be51 100644 --- a/homeassistant/components/blebox/light.py +++ b/homeassistant/components/blebox/light.py @@ -11,7 +11,7 @@ from blebox_uniapi.light import BleboxColorMode from homeassistant.components.light import ( ATTR_BRIGHTNESS, - ATTR_COLOR_TEMP, + ATTR_COLOR_TEMP_KELVIN, ATTR_EFFECT, ATTR_RGB_COLOR, ATTR_RGBW_COLOR, @@ -22,6 +22,7 @@ from homeassistant.components.light import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.util import color as color_util from . import BleBoxConfigEntry from .entity import BleBoxEntity @@ -58,8 +59,8 @@ COLOR_MODE_MAP = { class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): """Representation of BleBox lights.""" - _attr_max_mireds = 370 # 1,000,000 divided by 2700 Kelvin = 370 Mireds - _attr_min_mireds = 154 # 1,000,000 divided by 6500 Kelvin = 154 Mireds + _attr_min_color_temp_kelvin = 2700 # 370 Mireds + _attr_max_color_temp_kelvin = 6500 # 154 Mireds def __init__(self, feature: blebox_uniapi.light.Light) -> None: """Initialize a BleBox light.""" @@ -78,9 +79,9 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): return self._feature.brightness @property - def color_temp(self): - """Return color temperature.""" - return self._feature.color_temp + def color_temp_kelvin(self) -> int: + """Return the color temperature value in Kelvin.""" + return color_util.color_temperature_mired_to_kelvin(self._feature.color_temp) @property def color_mode(self): @@ -136,7 +137,7 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): rgbw = kwargs.get(ATTR_RGBW_COLOR) brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) - color_temp = kwargs.get(ATTR_COLOR_TEMP) + color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN) rgbww = kwargs.get(ATTR_RGBWW_COLOR) feature = self._feature value = feature.sensible_on_value @@ -144,9 +145,10 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): if rgbw is not None: value = list(rgbw) - if color_temp is not None: + if color_temp_kelvin is not None: value = feature.return_color_temp_with_brightness( - int(color_temp), self.brightness + int(color_util.color_temperature_kelvin_to_mired(color_temp_kelvin)), + self.brightness, ) if rgbww is not None: @@ -158,9 +160,12 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): value = list(rgb) if brightness is not None: - if self.color_mode == ATTR_COLOR_TEMP: + if self.color_mode == ColorMode.COLOR_TEMP: value = feature.return_color_temp_with_brightness( - self.color_temp, brightness + color_util.color_temperature_kelvin_to_mired( + self.color_temp_kelvin + ), + brightness, ) else: value = feature.apply_brightness(value, brightness)