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

Skip to content

Fix fan speed level when off and derive smart fan module from common fan interface #957

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 6, 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
5 changes: 3 additions & 2 deletions kasa/smart/modules/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from typing import TYPE_CHECKING

from ...feature import Feature
from ...interfaces.fan import Fan as FanInterface
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


class Fan(SmartModule):
class Fan(SmartModule, FanInterface):
"""Implementation of fan_control module."""

REQUIRED_COMPONENT = "fan_control"
Expand Down Expand Up @@ -54,7 +55,7 @@ def query(self) -> dict:
@property
def fan_speed_level(self) -> int:
"""Return fan speed level."""
return self.data["fan_speed_level"]
return 0 if self.data["device_on"] is False else self.data["fan_speed_level"]

async def set_fan_speed_level(self, level: int):
"""Set fan speed level, 0 for off, 1-4 for on."""
Expand Down
5 changes: 5 additions & 0 deletions kasa/tests/smart/modules/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ async def test_fan_module(dev: SmartDevice, mocker: MockerFixture):
assert fan.fan_speed_level == 1
assert device.is_on

# Check that if the device is off the speed level is 0.
await device.set_state(False)
await dev.update()
assert fan.fan_speed_level == 0

await fan.set_fan_speed_level(4)
await dev.update()
assert fan.fan_speed_level == 4
Expand Down
Loading