FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add fan control module · python-kasa/python-kasa@98e9f3d · GitHub

Repository navigation

Commit 98e9f3d

Browse files
committed
Add fan control module
1 parent cebe40d commit 98e9f3d

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎kasa/device_type.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DeviceType(Enum):
1717
LightStrip = "lightstrip"
1818
Sensor = "sensor"
1919
Hub = "hub"
20+
Fan = "fan"
2021
Unknown = "unknown"
2122

2223
@staticmethod

‎kasa/smart/modules/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .colortemp import ColorTemperatureModule
99
from .devicemodule import DeviceModule
1010
from .energymodule import EnergyModule
11+
from .fanmodule import FanModule
1112
from .firmware import Firmware
1213
from .humidity import HumiditySensor
1314
from .ledmodule import LedModule
@@ -29,6 +30,7 @@
2930
"AutoOffModule",
3031
"LedModule",
3132
"Brightness",
33+
"FanModule",
3234
"Firmware",
3335
"CloudModule",
3436
"LightTransitionModule",

‎kasa/smart/modules/fanmodule.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Implementation of fan_control module."""
2+
from typing import TYPE_CHECKING, Dict
3+
4+
from ...feature import Feature, FeatureType
5+
from ..smartmodule import SmartModule
6+
7+
if TYPE_CHECKING:
8+
from ..smartdevice import SmartDevice
9+
10+
11+
class FanModule(SmartModule):
12+
"""Implementation of fan_control module."""
13+
14+
REQUIRED_COMPONENT = "fan_control"
15+
16+
def __init__(self, device: "SmartDevice", module: str):
17+
super().__init__(device, module)
18+
19+
self._add_feature(
20+
Feature(
21+
device,
22+
"Fan speed level",
23+
container=self,
24+
attribute_getter="fan_speed_level",
25+
attribute_setter="set_fan_speed_level",
26+
icon="mdi:fan",
27+
type=FeatureType.Number,
28+
minimum_value=1,
29+
maximum_value=4,
30+
)
31+
)
32+
self._add_feature(
33+
Feature(
34+
device,
35+
"Fan sleep mode",
36+
container=self,
37+
attribute_getter="sleep_mode",
38+
attribute_setter="set_sleep_mode",
39+
icon="mdi:sleep",
40+
)
41+
)
42+
43+
def query(self) -> Dict:
44+
"""Query to execute during the update cycle."""
45+
return {}
46+
47+
@property
48+
def fan_speed_level(self) -> int:
49+
"""Return fan speed level."""
50+
return self.data["fan_speed_level"]
51+
52+
async def set_fan_speed_level(self, level: int):
53+
"""Set fan speed level."""
54+
if level < 1 or level > 4:
55+
raise ValueError("Invalid level, should be in range 1-4.")
56+
return await self.call("set_device_info", {"fan_speed_level": level})
57+
58+
@property
59+
def sleep_mode(self) -> bool:
60+
"""Return sleep mode status."""
61+
return self.data["fan_sleep_mode_on"]
62+
63+
async def set_sleep_mode(self, on: bool):
64+
"""Set sleep mode."""
65+
return await self.call("set_device_info", {"fan_sleep_mode_on": on})

‎kasa/smart/smartchilddevice.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def device_type(self) -> DeviceType:
4848
child_device_map = {
4949
"plug.powerstrip.sub-plug": DeviceType.Plug,
5050
"subg.trigger.temp-hmdt-sensor": DeviceType.Sensor,
51+
"kasa.switch.outlet.sub-fan": DeviceType.Fan,
52+
"kasa.switch.outlet.sub-dimmer": DeviceType.Dimmer,
5153
}
5254
dev_type = child_device_map.get(self.sys_info["category"])
5355
if dev_type is None:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL