mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Fix light color mode in tplink (#108760)
This commit is contained in:
parent
dc672ff62c
commit
4a2a7872fb
@ -17,6 +17,7 @@ from homeassistant.components.light import (
|
|||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
LightEntityFeature,
|
LightEntityFeature,
|
||||||
|
filter_supported_color_modes,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -181,7 +182,7 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||||||
self._attr_unique_id = legacy_device_id(device)
|
self._attr_unique_id = legacy_device_id(device)
|
||||||
else:
|
else:
|
||||||
self._attr_unique_id = device.mac.replace(":", "").upper()
|
self._attr_unique_id = device.mac.replace(":", "").upper()
|
||||||
modes: set[ColorMode] = set()
|
modes: set[ColorMode] = {ColorMode.ONOFF}
|
||||||
if device.is_variable_color_temp:
|
if device.is_variable_color_temp:
|
||||||
modes.add(ColorMode.COLOR_TEMP)
|
modes.add(ColorMode.COLOR_TEMP)
|
||||||
temp_range = device.valid_temperature_range
|
temp_range = device.valid_temperature_range
|
||||||
@ -191,9 +192,7 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||||||
modes.add(ColorMode.HS)
|
modes.add(ColorMode.HS)
|
||||||
if device.is_dimmable:
|
if device.is_dimmable:
|
||||||
modes.add(ColorMode.BRIGHTNESS)
|
modes.add(ColorMode.BRIGHTNESS)
|
||||||
if not modes:
|
self._attr_supported_color_modes = filter_supported_color_modes(modes)
|
||||||
modes.add(ColorMode.ONOFF)
|
|
||||||
self._attr_supported_color_modes = modes
|
|
||||||
self._async_update_attrs()
|
self._async_update_attrs()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -86,7 +86,7 @@ async def test_color_light(
|
|||||||
attributes = state.attributes
|
attributes = state.attributes
|
||||||
assert attributes[ATTR_BRIGHTNESS] == 128
|
assert attributes[ATTR_BRIGHTNESS] == 128
|
||||||
assert attributes[ATTR_COLOR_MODE] == "hs"
|
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_MIN_MIREDS] == 111
|
||||||
assert attributes[ATTR_MAX_MIREDS] == 250
|
assert attributes[ATTR_MAX_MIREDS] == 250
|
||||||
assert attributes[ATTR_HS_COLOR] == (10, 30)
|
assert attributes[ATTR_HS_COLOR] == (10, 30)
|
||||||
@ -163,7 +163,7 @@ async def test_color_light_no_temp(hass: HomeAssistant) -> None:
|
|||||||
attributes = state.attributes
|
attributes = state.attributes
|
||||||
assert attributes[ATTR_BRIGHTNESS] == 128
|
assert attributes[ATTR_BRIGHTNESS] == 128
|
||||||
assert attributes[ATTR_COLOR_MODE] == "hs"
|
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_HS_COLOR] == (10, 30)
|
||||||
assert attributes[ATTR_RGB_COLOR] == (255, 191, 178)
|
assert attributes[ATTR_RGB_COLOR] == (255, 191, 178)
|
||||||
assert attributes[ATTR_XY_COLOR] == (0.42, 0.336)
|
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_BRIGHTNESS] == 128
|
||||||
assert attributes[ATTR_COLOR_MODE] == "color_temp"
|
assert attributes[ATTR_COLOR_MODE] == "color_temp"
|
||||||
if bulb.is_color:
|
if bulb.is_color:
|
||||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [
|
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["color_temp", "hs"]
|
||||||
"brightness",
|
|
||||||
"color_temp",
|
|
||||||
"hs",
|
|
||||||
]
|
|
||||||
else:
|
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_MIN_MIREDS] == 111
|
||||||
assert attributes[ATTR_MAX_MIREDS] == 250
|
assert attributes[ATTR_MAX_MIREDS] == 250
|
||||||
assert attributes[ATTR_COLOR_TEMP_KELVIN] == 4000
|
assert attributes[ATTR_COLOR_TEMP_KELVIN] == 4000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user