Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Do not send light_on value to iot bulb set_state #1090

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 3 commits into from
Jul 31, 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
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kasa/iot/iotbulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ async def _set_light_state(
self, state: dict, *, transition: int | None = None
) -> dict:
"""Set the light state."""
state = {**state}
if transition is not None:
state["transition_period"] = transition

Expand Down
2 changes: 2 additions & 0 deletions kasa/iot/modules/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ async def set_state(self, state: LightState) -> dict:
state_dict["on_off"] = 1
else:
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)

@property
Expand Down
18 changes: 17 additions & 1 deletion kasa/tests/test_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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 .conftest import (
Expand Down Expand Up @@ -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
@turn_on
async def test_invalid_hsv(dev: Device, turn_on):
Expand Down
Loading