Fix color temperature setting in broadlink light (#101251)

This commit is contained in:
Erik Montnemery 2023-10-02 14:12:06 +02:00 committed by Franck Nijhof
parent 63b5ba6b3a
commit ad53ff037e
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3

View file

@ -6,7 +6,7 @@ from broadlink.exceptions import BroadlinkException
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_HS_COLOR,
ColorMode,
LightEntity,
@ -45,6 +45,8 @@ class BroadlinkLight(BroadlinkEntity, LightEntity):
_attr_has_entity_name = True
_attr_name = None
_attr_min_color_temp_kelvin = 2700
_attr_max_color_temp_kelvin = 6500
def __init__(self, device):
"""Initialize the light."""
@ -79,7 +81,7 @@ class BroadlinkLight(BroadlinkEntity, LightEntity):
self._attr_hs_color = [data["hue"], data["saturation"]]
if "colortemp" in data:
self._attr_color_temp = round((data["colortemp"] - 2700) / 100 + 153)
self._attr_color_temp_kelvin = data["colortemp"]
if "bulb_colormode" in data:
if data["bulb_colormode"] == BROADLINK_COLOR_MODE_RGB:
@ -107,9 +109,9 @@ class BroadlinkLight(BroadlinkEntity, LightEntity):
state["saturation"] = int(hs_color[1])
state["bulb_colormode"] = BROADLINK_COLOR_MODE_RGB
elif ATTR_COLOR_TEMP in kwargs:
color_temp = kwargs[ATTR_COLOR_TEMP]
state["colortemp"] = (color_temp - 153) * 100 + 2700
elif ATTR_COLOR_TEMP_KELVIN in kwargs:
color_temp = kwargs[ATTR_COLOR_TEMP_KELVIN]
state["colortemp"] = color_temp
state["bulb_colormode"] = BROADLINK_COLOR_MODE_WHITE
await self._async_set_state(state)