mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
Do not send light_on value to iot bulb set_state (#1090)
Passing this extra value caused the `ignore_default` check in the `IotBulb._set_light_state` method to fail which causes the device to come back on to the default state.
This commit is contained in:
parent
cb7e904d30
commit
cb0077f634
@ -326,6 +326,7 @@ class IotBulb(IotDevice):
|
|||||||
self, state: dict, *, transition: int | None = None
|
self, state: dict, *, transition: int | None = None
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Set the light state."""
|
"""Set the light state."""
|
||||||
|
state = {**state}
|
||||||
if transition is not None:
|
if transition is not None:
|
||||||
state["transition_period"] = transition
|
state["transition_period"] = transition
|
||||||
|
|
||||||
|
@ -230,6 +230,8 @@ class Light(IotModule, LightInterface):
|
|||||||
state_dict["on_off"] = 1
|
state_dict["on_off"] = 1
|
||||||
else:
|
else:
|
||||||
state_dict["on_off"] = int(state.light_on)
|
state_dict["on_off"] = int(state.light_on)
|
||||||
|
# Remove the light_on from the dict
|
||||||
|
state_dict.pop("light_on", None)
|
||||||
return await bulb._set_light_state(state_dict, transition=transition)
|
return await bulb._set_light_state(state_dict, transition=transition)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -9,7 +9,7 @@ from voluptuous import (
|
|||||||
Schema,
|
Schema,
|
||||||
)
|
)
|
||||||
|
|
||||||
from kasa import Device, DeviceType, IotLightPreset, KasaException, Module
|
from kasa import Device, DeviceType, IotLightPreset, KasaException, LightState, Module
|
||||||
from kasa.iot import IotBulb, IotDimmer
|
from kasa.iot import IotBulb, IotDimmer
|
||||||
|
|
||||||
from .conftest import (
|
from .conftest import (
|
||||||
@ -96,6 +96,22 @@ async def test_set_hsv_transition(dev: IotBulb, mocker):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bulb_iot
|
||||||
|
async def test_light_set_state(dev: IotBulb, mocker):
|
||||||
|
"""Testing setting LightState on the light module."""
|
||||||
|
light = dev.modules.get(Module.Light)
|
||||||
|
assert light
|
||||||
|
set_light_state = mocker.spy(dev, "_set_light_state")
|
||||||
|
state = LightState(light_on=True)
|
||||||
|
await light.set_state(state)
|
||||||
|
|
||||||
|
set_light_state.assert_called_with({"on_off": 1}, transition=None)
|
||||||
|
state = LightState(light_on=False)
|
||||||
|
await light.set_state(state)
|
||||||
|
|
||||||
|
set_light_state.assert_called_with({"on_off": 0}, transition=None)
|
||||||
|
|
||||||
|
|
||||||
@color_bulb
|
@color_bulb
|
||||||
@turn_on
|
@turn_on
|
||||||
async def test_invalid_hsv(dev: Device, turn_on):
|
async def test_invalid_hsv(dev: Device, turn_on):
|
||||||
|
Loading…
Reference in New Issue
Block a user