8000 Add PIR&LAS for wall switches mentioning PIR support (#1227) · python-kasa/python-kasa@b2f3971 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2f3971

Browse files
authored
Add PIR&LAS for wall switches mentioning PIR support (#1227)
Some devices (like KS200M) support ambient and motion, but as they are detected as wall switches, they don't get the modules added. This PR enables the respective modules for wall switches when the `dev_name` contains `PIR`.
1 parent 0360107 commit b2f3971

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

kasa/iot/iotplug.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..module import Module
1010
from ..protocol import BaseProtocol
1111
from .iotdevice import IotDevice, requires_update
12-
from .modules import Antitheft, Cloud, Led, Schedule, Time, Usage
12+
from .modules import AmbientLight, Antitheft, Cloud, Led, Motion, Schedule, Time, Usage
1313

1414
_LOGGER = logging.getLogger(__name__)
1515

@@ -92,3 +92,12 @@ def __init__(
9292
) -> None:
9393
super().__init__(host=host, config=config, protocol=protocol)
9494
self._device_type = DeviceType.WallSwitch
95+
96+
async def _initialize_modules(self) -> None:
97+
"""Initialize modules."""
98+
await super()._initialize_modules()
99+
if (dev_name := self.sys_info["dev_name"]) and "PIR" in dev_name:
100+
self.add_module(Module.IotMotion, Motion(self, "smartlife.iot.PIR"))
101+
self.add_module(
102+
Module.IotAmbientLight, AmbientLight(self, "smartlife.iot.LAS")
103+
)

kasa/tests/iot/test_wallswitch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from kasa.tests.device_fixtures import wallswitch_iot
2+
3+
4+
@wallswitch_iot
5+
def test_wallswitch_motion(dev):
6+
"""Check that wallswitches with motion sensor get modules enabled."""
7+
has_motion = "PIR" in dev.sys_info["dev_name"]
8+
assert "motion" in dev.modules if has_motion else True
9+
assert "ambient" in dev.modules if has_motion else True

0 commit comments

Comments
 (0)
0