Fix light color mode in tplink (#109831)
This commit is contained in:
parent
5d1da0b3e4
commit
2e194c4ec3
1 changed files with 11 additions and 7 deletions
|
@ -163,6 +163,7 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||
|
||||
_attr_supported_features = LightEntityFeature.TRANSITION
|
||||
_attr_name = None
|
||||
_fixed_color_mode: ColorMode | None = None
|
||||
|
||||
device: SmartBulb
|
||||
|
||||
|
@ -193,6 +194,9 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||
if device.is_dimmable:
|
||||
modes.add(ColorMode.BRIGHTNESS)
|
||||
self._attr_supported_color_modes = filter_supported_color_modes(modes)
|
||||
if len(self._attr_supported_color_modes) == 1:
|
||||
# If the light supports only a single color mode, set it now
|
||||
self._fixed_color_mode = next(iter(self._attr_supported_color_modes))
|
||||
self._async_update_attrs()
|
||||
|
||||
@callback
|
||||
|
@ -273,14 +277,14 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||
|
||||
def _determine_color_mode(self) -> ColorMode:
|
||||
"""Return the active color mode."""
|
||||
if self.device.is_color:
|
||||
if self.device.is_variable_color_temp and self.device.color_temp:
|
||||
return ColorMode.COLOR_TEMP
|
||||
return ColorMode.HS
|
||||
if self.device.is_variable_color_temp:
|
||||
return ColorMode.COLOR_TEMP
|
||||
if self._fixed_color_mode:
|
||||
# The light supports only a single color mode, return it
|
||||
return self._fixed_color_mode
|
||||
|
||||
return ColorMode.BRIGHTNESS
|
||||
# The light supports both color temp and color, determine which on is active
|
||||
if self.device.is_variable_color_temp and self.device.color_temp:
|
||||
return ColorMode.COLOR_TEMP
|
||||
return ColorMode.HS
|
||||
|
||||
@callback
|
||||
def _async_update_attrs(self) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue