mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-23 03:33:35 +00:00
Fix switching off light effects for iot lights strips (#961)
Fixes the newly implemented method to turn off active effects on iot devices
This commit is contained in:
parent
e1e2a396b8
commit
b8c1b39cf0
@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from ...interfaces.lighteffect import LightEffect as LightEffectInterface
|
from ...interfaces.lighteffect import LightEffect as LightEffectInterface
|
||||||
|
from ...module import Module
|
||||||
from ..effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
|
from ..effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
|
||||||
from ..iotmodule import IotModule
|
from ..iotmodule import IotModule
|
||||||
|
|
||||||
@ -59,8 +60,13 @@ class LightEffect(IotModule, LightEffectInterface):
|
|||||||
:param int transition: The wanted transition time
|
:param int transition: The wanted transition time
|
||||||
"""
|
"""
|
||||||
if effect == self.LIGHT_EFFECTS_OFF:
|
if effect == self.LIGHT_EFFECTS_OFF:
|
||||||
effect_dict = dict(self.data["lighting_effect_state"])
|
light_module = self._device.modules[Module.Light]
|
||||||
effect_dict["enable"] = 0
|
effect_off_state = light_module.state
|
||||||
|
if brightness is not None:
|
||||||
|
effect_off_state.brightness = brightness
|
||||||
|
if transition is not None:
|
||||||
|
effect_off_state.transition = transition
|
||||||
|
await light_module.set_state(effect_off_state)
|
||||||
elif effect not in EFFECT_MAPPING_V1:
|
elif effect not in EFFECT_MAPPING_V1:
|
||||||
raise ValueError(f"The effect {effect} is not a built in effect.")
|
raise ValueError(f"The effect {effect} is not a built in effect.")
|
||||||
else:
|
else:
|
||||||
|
@ -317,6 +317,12 @@ class FakeIotTransport(BaseTransport):
|
|||||||
_LOGGER.debug("New light state: %s", new_state)
|
_LOGGER.debug("New light state: %s", new_state)
|
||||||
self.proto["system"]["get_sysinfo"]["light_state"] = 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):
|
def set_preferred_state(self, new_state, *args):
|
||||||
"""Implement set_preferred_state."""
|
"""Implement set_preferred_state."""
|
||||||
self.proto["system"]["get_sysinfo"]["preferred_state"][new_state["index"]] = (
|
self.proto["system"]["get_sysinfo"]["preferred_state"][new_state["index"]] = (
|
||||||
|
@ -78,7 +78,7 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
|
|||||||
assert light_effect_module
|
assert light_effect_module
|
||||||
feat = dev.features["light_effect"]
|
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
|
effect_list = light_effect_module.effect_list
|
||||||
assert "Off" in effect_list
|
assert "Off" in effect_list
|
||||||
assert effect_list.index("Off") == 0
|
assert effect_list.index("Off") == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user