Fix Tradfri color bulbs losing HS color mode (#185197)

This commit is contained in:
Franck Nijhof
2026-10-09 12:16:13 +02:00
committed by GitHub
parent 2e895a7c72
commit 659bafa99e
3 changed files with 63 additions and 5 deletions
+10 -5
View File
@@ -74,7 +74,7 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
# Calculate supported color modes
modes: set[ColorMode] = {ColorMode.ONOFF}
if self._device_data.supports_hsb_xy_color:
if self._supports_hs_color:
modes.add(ColorMode.HS)
if self._device_data.supports_color_temp:
modes.add(ColorMode.COLOR_TEMP)
@@ -91,6 +91,12 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
self._device_control.max_mireds
)
@property
def _supports_hs_color(self) -> bool:
"""Return if the light supports setting a hue and saturation."""
# supports_hsb_xy_color is False for color bulbs that also report mireds
return self._device_data.raw.color_hue is not None
@override
def _refresh(self) -> None:
"""Refresh the device."""
@@ -179,7 +185,7 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
dimmer_command = self._device_control.set_state(True)
color_command = None
if ATTR_HS_COLOR in kwargs and self._device_data.supports_hsb_xy_color:
if ATTR_HS_COLOR in kwargs and self._supports_hs_color:
hue = int(kwargs[ATTR_HS_COLOR][0] * (self._device_control.max_hue / 360))
sat = int(
kwargs[ATTR_HS_COLOR][1] * (self._device_control.max_saturation / 100)
@@ -191,8 +197,7 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
temp_command = None
if ATTR_COLOR_TEMP_KELVIN in kwargs and (
self._device_data.supports_color_temp
or self._device_data.supports_hsb_xy_color
self._device_data.supports_color_temp or self._supports_hs_color
):
temp_k = kwargs[ATTR_COLOR_TEMP_KELVIN]
# White Spectrum bulb
@@ -208,7 +213,7 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
transition_time = None
# Color bulb (CWS)
# color_temp needs to be set with hue/saturation
elif self._device_data.supports_hsb_xy_color:
elif self._supports_hs_color:
hs_color = color_util.color_temperature_to_hs(temp_k)
hue = int(hs_color[0] * (self._device_control.max_hue / 360))
sat = int(hs_color[1] * (self._device_control.max_saturation / 100))
@@ -0,0 +1,29 @@
{
"3": {
"0": "IKEA of Sweden",
"1": "TRADFRI bulb GU10 CWS 345lm",
"2": "",
"3": "1.3.002",
"6": 1
},
"3311": [
{
"5706": "f1e0b5",
"5707": 5427,
"5708": 42596,
"5709": 30015,
"5710": 26870,
"5711": 370,
"5850": 1,
"5851": 250,
"9003": 0
}
],
"5750": 2,
"9001": "Test CWS color temp",
"9002": 1509924799,
"9003": 65542,
"9019": 1,
"9020": 1510011206,
"9054": 0
}
+24
View File
@@ -50,6 +50,12 @@ def bulb_cws() -> str:
return load_fixture("bulb_cws.json", DOMAIN)
@pytest.fixture(scope="module")
def bulb_cws_color_temp() -> str:
"""Return a color bulb that also reports a color temperature."""
return load_fixture("bulb_cws_color_temp.json", DOMAIN)
@pytest.mark.parametrize(
("device", "entity_id", "state_attributes"),
[
@@ -84,6 +90,16 @@ def bulb_cws() -> str:
ATTR_COLOR_MODE: ColorMode.HS,
},
),
(
"bulb_cws_color_temp",
"light.test_cws_color_temp",
{
ATTR_BRIGHTNESS: 250,
ATTR_HS_COLOR: (29.812, 65.252),
ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP, ColorMode.HS],
ATTR_COLOR_MODE: ColorMode.HS,
},
),
],
indirect=["device"],
)
@@ -190,6 +206,13 @@ async def test_light_available(
{"hs_color": [300, 100]},
{"hs_color": [300, 100]},
),
# hs_color on a color bulb that also reports a color temperature
(
"bulb_cws_color_temp",
"light.test_cws_color_temp",
{"hs_color": [300, 100]},
{"hs_color": [300, 100]},
),
# ct + brightness
(
"bulb_ws",
@@ -229,6 +252,7 @@ async def test_light_available(
"color_temp_kelvin > 4000",
"color_temp_kelvin < 2202",
"hs_color",
"hs_color (color bulb with color temp)",
"ct + brightness",
"ct + brightness (no temp support)",
"ct + brightness (no temp or color support)",