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`.
This commit is contained in:
Teemu R. 2024-11-03 16:45:48 +01:00 committed by GitHub
parent 0360107e3f
commit b2f3971a4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -9,7 +9,7 @@ from ..deviceconfig import DeviceConfig
from ..module import Module from ..module import Module
from ..protocol import BaseProtocol from ..protocol import BaseProtocol
from .iotdevice import IotDevice, requires_update from .iotdevice import IotDevice, requires_update
from .modules import Antitheft, Cloud, Led, Schedule, Time, Usage from .modules import AmbientLight, Antitheft, Cloud, Led, Motion, Schedule, Time, Usage
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -92,3 +92,12 @@ class IotWallSwitch(IotPlug):
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self._device_type = DeviceType.WallSwitch self._device_type = DeviceType.WallSwitch
async def _initialize_modules(self) -> None:
"""Initialize modules."""
await super()._initialize_modules()
if (dev_name := self.sys_info["dev_name"]) and "PIR" in dev_name:
self.add_module(Module.IotMotion, Motion(self, "smartlife.iot.PIR"))
self.add_module(
Module.IotAmbientLight, AmbientLight(self, "smartlife.iot.LAS")
)

View File

@ -0,0 +1,9 @@
from kasa.tests.device_fixtures import wallswitch_iot
@wallswitch_iot
def test_wallswitch_motion(dev):
"""Check that wallswitches with motion sensor get modules enabled."""
has_motion = "PIR" in dev.sys_info["dev_name"]
assert "motion" in dev.modules if has_motion else True
assert "ambient" in dev.modules if has_motion else True