Use shorthand attrs for more tplink light attributes (#106399)

* Use shorthand attrs for more tplink light attributes

supported_color_modes and features were having to be recalced every time
state was written

* preen
This commit is contained in:
J. Nick Koston 2023-12-25 20:28:40 -10:00 committed by GitHub
parent 18ace16744
commit b800475242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,6 +182,16 @@ 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()
if device.is_variable_color_temp:
modes.add(ColorMode.COLOR_TEMP)
if device.is_color:
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
@callback
def _async_extract_brightness_transition(
@ -267,22 +277,6 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
hue, saturation, _ = self.device.hsv
return hue, saturation
@property
def supported_color_modes(self) -> set[ColorMode]:
"""Return list of available color modes."""
modes: set[ColorMode] = set()
if self.device.is_variable_color_temp:
modes.add(ColorMode.COLOR_TEMP)
if self.device.is_color:
modes.add(ColorMode.HS)
if self.device.is_dimmable:
modes.add(ColorMode.BRIGHTNESS)
if not modes:
modes.add(ColorMode.ONOFF)
return modes
@property
def color_mode(self) -> ColorMode:
"""Return the active color mode."""
@ -300,11 +294,7 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
"""Representation of a TPLink Smart Light Strip."""
device: SmartLightStrip
@property
def supported_features(self) -> LightEntityFeature:
"""Flag supported features."""
return super().supported_features | LightEntityFeature.EFFECT
_attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT
@property
def effect_list(self) -> list[str] | None: