10000 Fix switching off light effects for iot lights strips by sdb9696 · Pull Request #961 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Fix switching off light effects for iot lights strips #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
8000
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions kasa/iot/modules/lighteffect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from ...interfaces.lighteffect import LightEffect as LightEffectInterface
from ...module import Module
from ..effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
from ..iotmodule import IotModule

Expand Down Expand Up @@ -59,19 +60,24 @@
:param int transition: The wanted transition time
"""
if effect == self.LIGHT_EFFECTS_OFF:
effect_dict = dict(self.data["lighting_effect_state"])
effect_dict["enable"] = 0
light_module = self._device.modules[Module.Light]
effect_off_state = light_module.state
if brightness is not None:
effect_off_state.brightness = brightness

Check warning on line 66 in kasa/iot/modules/lighteffect.py

View check run for this annotation

Codecov / codecov/patch

kasa/iot/modules/lighteffect.py#L66

Added line #L66 was not covered by tests
if transition is not None:
effect_off_state.transition = transition

Check warning on line 68 in kasa/iot/modules/lighteffect.py

View check run for this annotation

Codecov / codecov/patch

kasa/iot/modules/lighteffect.py#L68

Added line #L68 was not covered by tests
await light_module.set_state(effect_off_state)
elif effect not in EFFECT_MAPPING_V1:
raise ValueError(f"The effect {effect} is not a built in effect.")
else:
effect_dict = EFFECT_MAPPING_V1[effect]

if brightness is not None:
effect_dict["brightness"] = brightness
if transition is not None:
effect_dict["transition"] = transition
if brightness is not None:
effect_dict["brightness"] = brightness
if transition is not None:
effect_dict["transition"] = transition

await self.set_custom_effect(effect_dict)
await self.set_custom_effect(effect_dict)

async def set_custom_effect(
self,
Expand Down
6 changes: 6 additions & 0 deletions kasa/tests/fakeprotocol_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ def transition_light_state(self, state_changes, *args):
_LOGGER.debug("New light state: %s", new_state)
self.proto["system"]["get_sysinfo"]["light_state"] = new_state

# Setting the light state on a device will turn off any active lighting effects.
if lighting_effect_state := self.proto["system"]["get_sysinfo"].get(
"lighting_effect_state"
):
lighting_effect_state["enable"] = 0

def set_preferred_state(self, new_state, *args):
"""Implement set_preferred_state."""
self.proto["system"]["get_sysinfo"]["preferred_state"][new_state["index"]] = (
Expand Down
2 changes: 1 addition & 1 deletion kasa/tests/test_common_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
assert light_effect_module
feat = dev.features["light_effect"]

call = mocker.spy(light_effect_module, "call")
call = mocker.spy(dev, "_query_helper")
effect_list = light_effect_module.effect_list
assert "Off" in effect_list
assert effect_list.index("Off") == 0
Expand Down
Loading
0