From 82fbe1226ebb295ac87d949753dd4d58ef7f3668 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:49:06 +0000 Subject: [PATCH] Do not return empty string for custom light effect name (#1491) --- kasa/interfaces/lighteffect.py | 3 ++- kasa/iot/modules/lighteffect.py | 13 ++----------- kasa/smart/modules/lightstripeffect.py | 12 +++--------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/kasa/interfaces/lighteffect.py b/kasa/interfaces/lighteffect.py index fa50dd3e..bfcd9be3 100644 --- a/kasa/interfaces/lighteffect.py +++ b/kasa/interfaces/lighteffect.py @@ -51,6 +51,7 @@ class LightEffect(Module, ABC): """Interface to represent a light effect module.""" LIGHT_EFFECTS_OFF = "Off" + LIGHT_EFFECTS_UNNAMED_CUSTOM = "Custom" def _initialize_features(self) -> None: """Initialize features.""" @@ -77,7 +78,7 @@ class LightEffect(Module, ABC): @property @abstractmethod def effect(self) -> str: - """Return effect state or name.""" + """Return effect name.""" @property @abstractmethod diff --git a/kasa/iot/modules/lighteffect.py b/kasa/iot/modules/lighteffect.py index cdfaaae1..3a41fb5f 100644 --- a/kasa/iot/modules/lighteffect.py +++ b/kasa/iot/modules/lighteffect.py @@ -12,20 +12,11 @@ class LightEffect(IotModule, LightEffectInterface): @property def effect(self) -> str: - """Return effect state. - - Example: - {'brightness': 50, - 'custom': 0, - 'enable': 0, - 'id': '', - 'name': ''} - """ + """Return effect name.""" eff = self.data["lighting_effect_state"] name = eff["name"] if eff["enable"]: - return name - + return name or self.LIGHT_EFFECTS_UNNAMED_CUSTOM return self.LIGHT_EFFECTS_OFF @property diff --git a/kasa/smart/modules/lightstripeffect.py b/kasa/smart/modules/lightstripeffect.py index 91d89188..34c1c20c 100644 --- a/kasa/smart/modules/lightstripeffect.py +++ b/kasa/smart/modules/lightstripeffect.py @@ -37,20 +37,14 @@ class LightStripEffect(SmartModule, SmartLightEffect): @property def effect(self) -> str: - """Return effect state. - - Example: - {'brightness': 50, - 'custom': 0, - 'enable': 0, - 'id': '', - 'name': ''} - """ + """Return effect name.""" eff = self.data["lighting_effect"] name = eff["name"] # When devices are unpaired effect name is softAP which is not in our list if eff["enable"] and name in self._effect_list: return name + if eff["enable"] and eff["custom"]: + return name or self.LIGHT_EFFECTS_UNNAMED_CUSTOM return self.LIGHT_EFFECTS_OFF @property