Migrate blebox lights to use Kelvin (#132787)
parent
cd420aee88
commit
a11bf5cce1
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue