mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Fix light color mode in tradfri (#108761)
This commit is contained in:
parent
4b2b4ae36b
commit
aaf1cc818a
@ -14,6 +14,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
|
from homeassistant.core import HomeAssistant
|
||||||
@ -51,6 +52,7 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
|
|||||||
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
_attr_supported_features = LightEntityFeature.TRANSITION
|
_attr_supported_features = LightEntityFeature.TRANSITION
|
||||||
|
_fixed_color_mode: ColorMode | None = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -72,18 +74,16 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
|
|||||||
self._hs_color = None
|
self._hs_color = None
|
||||||
|
|
||||||
# Calculate supported color modes
|
# Calculate supported color modes
|
||||||
self._attr_supported_color_modes: set[ColorMode] = set()
|
modes: set[ColorMode] = {ColorMode.ONOFF}
|
||||||
if self._device.light_control.can_set_color:
|
if self._device.light_control.can_set_color:
|
||||||
self._attr_supported_color_modes.add(ColorMode.HS)
|
modes.add(ColorMode.HS)
|
||||||
if self._device.light_control.can_set_temp:
|
if self._device.light_control.can_set_temp:
|
||||||
self._attr_supported_color_modes.add(ColorMode.COLOR_TEMP)
|
modes.add(ColorMode.COLOR_TEMP)
|
||||||
if (
|
if self._device.light_control.can_set_dimmer:
|
||||||
not self._attr_supported_color_modes
|
modes.add(ColorMode.BRIGHTNESS)
|
||||||
and self._device.light_control.can_set_dimmer
|
self._attr_supported_color_modes = filter_supported_color_modes(modes)
|
||||||
):
|
if len(self._attr_supported_color_modes) == 1:
|
||||||
# Must be the only supported mode according to docs for
|
self._fixed_color_mode = next(iter(self._attr_supported_color_modes))
|
||||||
# ColorMode.BRIGHTNESS
|
|
||||||
self._attr_supported_color_modes.add(ColorMode.BRIGHTNESS)
|
|
||||||
|
|
||||||
if self._device_control:
|
if self._device_control:
|
||||||
self._attr_min_mireds = self._device_control.min_mireds
|
self._attr_min_mireds = self._device_control.min_mireds
|
||||||
@ -100,6 +100,15 @@ class TradfriLight(TradfriBaseEntity, LightEntity):
|
|||||||
return False
|
return False
|
||||||
return cast(bool, self._device_data.state)
|
return cast(bool, self._device_data.state)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_mode(self) -> ColorMode | None:
|
||||||
|
"""Return the color mode of the light."""
|
||||||
|
if self._fixed_color_mode:
|
||||||
|
return self._fixed_color_mode
|
||||||
|
if self.hs_color:
|
||||||
|
return ColorMode.HS
|
||||||
|
return ColorMode.COLOR_TEMP
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self) -> int | None:
|
def brightness(self) -> int | None:
|
||||||
"""Return the brightness of the light."""
|
"""Return the brightness of the light."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user