From b800475242a0a2e6208102f6c9242069b2592196 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 25 Dec 2023 20:28:40 -1000 Subject: [PATCH] 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 --- homeassistant/components/tplink/light.py | 32 ++++++++---------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index db7e6ff355e..8e77c68a880 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -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: