Skip to content

Commit 8b05a22

Browse files
committed
Improve effect handling in LEDNETWFLight and Model0x56
- Update available property to use 'is not None' for clarity. - Add logging for unknown effects in LEDNETWFLight. - Handle unknown effects gracefully in Model0x56's set_effect method.
1 parent e766162 commit 8b05a22

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

custom_components/lednetwf_ble/light.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151

5252
@property
5353
def available(self):
54-
return self._instance.is_on != None
54+
return self._instance.is_on is not None
5555

5656
@property
5757
def brightness(self):
@@ -181,7 +181,12 @@ async def async_turn_on(self, **kwargs: Any) -> None:
181181
elif ATTR_RGB_COLOR in kwargs:
182182
await self._instance.set_rgb_color(kwargs[ATTR_RGB_COLOR], on_brightness)
183183
elif ATTR_EFFECT in kwargs and kwargs[ATTR_EFFECT] != EFFECT_OFF:
184-
await self._instance.set_effect(kwargs[ATTR_EFFECT], on_brightness)
184+
effect = kwargs[ATTR_EFFECT]
185+
# Don't try to set unknown effects
186+
if effect.startswith("Unknown Effect"):
187+
LOGGER.warning(f"Cannot set unknown effect: {effect}. Ignoring.")
188+
else:
189+
await self._instance.set_effect(effect, on_brightness)
185190
self.async_write_ha_state()
186191

187192
async def async_turn_off(self, **kwargs: Any) -> None:
@@ -213,5 +218,5 @@ def update_ha_state(self) -> None:
213218
# self._color_mode = ColorMode.RGB
214219
elif self.color_temp_kelvin is not None:
215220
self._color_mode = ColorMode.COLOR_TEMP
216-
self.available = self._instance.is_on != None
221+
self.available = self._instance.is_on is not None
217222
self.async_write_ha_state()

custom_components/lednetwf_ble/models/model_0x56.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,17 @@ def set_color(self, hs_color, brightness):
164164

165165
def set_effect(self, effect, brightness):
166166
# Returns the byte array to set the effect
167-
LOGGER.debug(f"Setting effect: {effect}")
167+
LOGGER.debug(f"Setting effect: {effect}")
168+
169+
# Handle unknown effects gracefully
170+
if effect.startswith("Unknown Effect"):
171+
LOGGER.warning(f"Attempt to set unknown effect: {effect}. Ignoring.")
172+
return None
173+
168174
if effect not in EFFECT_LIST_0x56:
169-
raise ValueError(f"Effect '{effect}' not in EFFECTS_LIST_0x53")
175+
LOGGER.error(f"Effect '{effect}' not in EFFECT_LIST_0x56")
176+
raise ValueError(f"Effect '{effect}' not in EFFECT_LIST_0x56")
177+
170178
self.effect = effect
171179
self.brightness = brightness
172180
#self.color_mode = XXX ColorMode.BRIGHTNESS # Don't set this here, we might want to change the color of the effects?

0 commit comments

Comments
 (0)