mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
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:
parent
18ace16744
commit
b800475242
@ -182,6 +182,16 @@ 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()
|
||||||
|
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
|
@callback
|
||||||
def _async_extract_brightness_transition(
|
def _async_extract_brightness_transition(
|
||||||
@ -267,22 +277,6 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||||||
hue, saturation, _ = self.device.hsv
|
hue, saturation, _ = self.device.hsv
|
||||||
return hue, saturation
|
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
|
@property
|
||||||
def color_mode(self) -> ColorMode:
|
def color_mode(self) -> ColorMode:
|
||||||
"""Return the active color mode."""
|
"""Return the active color mode."""
|
||||||
@ -300,11 +294,7 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
|
|||||||
"""Representation of a TPLink Smart Light Strip."""
|
"""Representation of a TPLink Smart Light Strip."""
|
||||||
|
|
||||||
device: SmartLightStrip
|
device: SmartLightStrip
|
||||||
|
_attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT
|
||||||
@property
|
|
||||||
def supported_features(self) -> LightEntityFeature:
|
|
||||||
"""Flag supported features."""
|
|
||||||
return super().supported_features | LightEntityFeature.EFFECT
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect_list(self) -> list[str] | None:
|
def effect_list(self) -> list[str] | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user