Skip to content

Commit b8c1b39

Browse files
authored
Fix switching off light effects for iot lights strips (#961)
Fixes the newly implemented method to turn off active effects on iot devices
1 parent e1e2a39 commit b8c1b39

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

kasa/iot/modules/lighteffect.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from ...interfaces.lighteffect import LightEffect as LightEffectInterface
6+
from ...module import Module
67
from ..effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
78
from ..iotmodule import IotModule
89

@@ -59,19 +60,24 @@ async def set_effect(
5960
:param int transition: The wanted transition time
6061
"""
6162
if effect == self.LIGHT_EFFECTS_OFF:
62-
effect_dict = dict(self.data["lighting_effect_state"])
63-
effect_dict["enable"] = 0
63+
light_module = self._device.modules[Module.Light]
64+
effect_off_state = light_module.state
65+
if brightness is not None:
66+
effect_off_state.brightness = brightness
67+
if transition is not None:
68+
effect_off_state.transition = transition
69+
await light_module.set_state(effect_off_state)
6470
elif effect not in EFFECT_MAPPING_V1:
6571
raise ValueError(f"The effect {effect} is not a built in effect.")
6672
else:
6773
effect_dict = EFFECT_MAPPING_V1[effect]
6874

69-
if brightness is not None:
70-
effect_dict["brightness"] = brightness
71-
if transition is not None:
72-
effect_dict["transition"] = transition
75+
if brightness is not None:
76+
effect_dict["brightness"] = brightness
77+
if transition is not None:
78+
effect_dict["transition"] = transition
7379

74-
await self.set_custom_effect(effect_dict)
80+
await self.set_custom_effect(effect_dict)
7581

7682
async def set_custom_effect(
7783
self,

kasa/tests/fakeprotocol_iot.py

+6
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ def transition_light_state(self, state_changes, *args):
317317
_LOGGER.debug("New light state: %s", new_state)
318318
self.proto["system"]["get_sysinfo"]["light_state"] = new_state
319319

320+
# Setting the light state on a device will turn off any active lighting effects.
321+
if lighting_effect_state := self.proto["system"]["get_sysinfo"].get(
322+
"lighting_effect_state"
323+
):
324+
lighting_effect_state["enable"] = 0
325+
320326
def set_preferred_state(self, new_state, *args):
321327
"""Implement set_preferred_state."""
322328
self.proto["system"]["get_sysinfo"]["preferred_state"][new_state["index"]] = (

kasa/tests/test_common_modules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
7878
assert light_effect_module
7979
feat = dev.features["light_effect"]
8080

81-
call = mocker.spy(light_effect_module, "call")
81+
call = mocker.spy(dev, "_query_helper")
8282
effect_list = light_effect_module.effect_list
8383
assert "Off" in effect_list
8484
assert effect_list.index("Off") == 0

0 commit comments

Comments
 (0)