diff --git a/kasa/module.py b/kasa/module.py index 2ca29307..754814ec 100644 --- a/kasa/module.py +++ b/kasa/module.py @@ -154,6 +154,7 @@ class Module(ABC): ) TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = ModuleName("TriggerLogs") + HomeKit: Final[ModuleName[smart.HomeKit]] = ModuleName("HomeKit") Matter: Final[ModuleName[smart.Matter]] = ModuleName("Matter") # SMARTCAM only modules diff --git a/kasa/smart/modules/__init__.py b/kasa/smart/modules/__init__.py index fd93c7c0..ae9fb68f 100644 --- a/kasa/smart/modules/__init__.py +++ b/kasa/smart/modules/__init__.py @@ -16,6 +16,7 @@ from .energy import Energy from .fan import Fan from .firmware import Firmware from .frostprotection import FrostProtection +from .homekit import HomeKit from .humiditysensor import HumiditySensor from .led import Led from .light import Light @@ -67,5 +68,6 @@ __all__ = [ "Thermostat", "SmartLightEffect", "OverheatProtection", + "HomeKit", "Matter", ] diff --git a/kasa/smart/modules/homekit.py b/kasa/smart/modules/homekit.py new file mode 100644 index 00000000..2df8db1f --- /dev/null +++ b/kasa/smart/modules/homekit.py @@ -0,0 +1,32 @@ +"""Implementation of homekit module.""" + +from __future__ import annotations + +from ...feature import Feature +from ..smartmodule import SmartModule + + +class HomeKit(SmartModule): + """Implementation of homekit module.""" + + QUERY_GETTER_NAME: str = "get_homekit_info" + REQUIRED_COMPONENT = "homekit" + + def _initialize_features(self) -> None: + """Initialize features after the initial update.""" + self._add_feature( + Feature( + self._device, + id="homekit_setup_code", + name="Homekit setup code", + container=self, + attribute_getter=lambda x: x.info["mfi_setup_code"], + type=Feature.Type.Sensor, + category=Feature.Category.Debug, + ) + ) + + @property + def info(self) -> dict[str, str]: + """Homekit mfi setup info.""" + return self.data diff --git a/kasa/smartcam/modules/__init__.py b/kasa/smartcam/modules/__init__.py index 5ac37584..a3f51c87 100644 --- a/kasa/smartcam/modules/__init__.py +++ b/kasa/smartcam/modules/__init__.py @@ -4,6 +4,7 @@ from .alarm import Alarm from .camera import Camera from .childdevice import ChildDevice from .device import DeviceModule +from .homekit import HomeKit from .led import Led from .matter import Matter from .pantilt import PanTilt @@ -17,5 +18,6 @@ __all__ = [ "Led", "PanTilt", "Time", + "HomeKit", "Matter", ] diff --git a/kasa/smartcam/modules/homekit.py b/kasa/smartcam/modules/homekit.py new file mode 100644 index 00000000..a35de4f9 --- /dev/null +++ b/kasa/smartcam/modules/homekit.py @@ -0,0 +1,16 @@ +"""Implementation of homekit module.""" + +from __future__ import annotations + +from ..smartcammodule import SmartCamModule + + +class HomeKit(SmartCamModule): + """Implementation of homekit module.""" + + REQUIRED_COMPONENT = "homekit" + + @property + def info(self) -> dict[str, str]: + """Not supported, return empty dict.""" + return {} diff --git a/tests/fakeprotocol_smart.py b/tests/fakeprotocol_smart.py index a34384a2..c0222b99 100644 --- a/tests/fakeprotocol_smart.py +++ b/tests/fakeprotocol_smart.py @@ -114,6 +114,15 @@ class FakeSmartTransport(BaseTransport): "type": 0, }, ), + "get_homekit_info": ( + "homekit", + { + "mfi_setup_code": "000-00-000", + "mfi_setup_id": "0000", + "mfi_token_token": "000000000000000000000000000000000", + "mfi_token_uuid": "00000000-0000-0000-0000-000000000000", + }, + ), "get_auto_update_info": ( "firmware", {"enable": True, "random_range": 120, "time": 180}, diff --git a/tests/smart/modules/test_homekit.py b/tests/smart/modules/test_homekit.py new file mode 100644 index 00000000..81992398 --- /dev/null +++ b/tests/smart/modules/test_homekit.py @@ -0,0 +1,16 @@ +from kasa import Module +from kasa.smart import SmartDevice + +from ...device_fixtures import parametrize + +homekit = parametrize( + "has homekit", component_filter="homekit", protocol_filter={"SMART"} +) + + +@homekit +async def test_info(dev: SmartDevice): + """Test homekit info.""" + homekit = dev.modules.get(Module.HomeKit) + assert homekit + assert homekit.info