Fix light color mode in tplink (#108760)

This commit is contained in:
Erik Montnemery 2024-01-24 15:28:40 +01:00 committed by GitHub
parent dc672ff62c
commit 4a2a7872fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 12 deletions

View file

@ -17,6 +17,7 @@ from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
filter_supported_color_modes,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
@ -181,7 +182,7 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
self._attr_unique_id = legacy_device_id(device)
else:
self._attr_unique_id = device.mac.replace(":", "").upper()
modes: set[ColorMode] = set()
modes: set[ColorMode] = {ColorMode.ONOFF}
if device.is_variable_color_temp:
modes.add(ColorMode.COLOR_TEMP)
temp_range = device.valid_temperature_range
@ -191,9 +192,7 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
modes.add(ColorMode.HS)
if device.is_dimmable:
modes.add(ColorMode.BRIGHTNESS)
if not modes:
modes.add(ColorMode.ONOFF)
self._attr_supported_color_modes = modes
self._attr_supported_color_modes = filter_supported_color_modes(modes)
self._async_update_attrs()
@callback

View file

@ -86,7 +86,7 @@ async def test_color_light(
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "hs"
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["brightness", "color_temp", "hs"]
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp", "hs"]
assert attributes[ATTR_MIN_MIREDS] == 111
assert attributes[ATTR_MAX_MIREDS] == 250
assert attributes[ATTR_HS_COLOR] == (10, 30)
@ -163,7 +163,7 @@ async def test_color_light_no_temp(hass: HomeAssistant) -> None:
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "hs"
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["brightness", "hs"]
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["hs"]
assert attributes[ATTR_HS_COLOR] == (10, 30)
assert attributes[ATTR_RGB_COLOR] == (255, 191, 178)
assert attributes[ATTR_XY_COLOR] == (0.42, 0.336)
@ -225,13 +225,9 @@ async def test_color_temp_light(
assert attributes[ATTR_BRIGHTNESS] == 128
assert attributes[ATTR_COLOR_MODE] == "color_temp"
if bulb.is_color:
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [
"brightness",
"color_temp",
"hs",
]
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp", "hs"]
else:
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["brightness", "color_temp"]
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp"]
assert attributes[ATTR_MIN_MIREDS] == 111
assert attributes[ATTR_MAX_MIREDS] == 250
assert attributes[ATTR_COLOR_TEMP_KELVIN] == 4000