8000 Add bare bones homekit modules smart and smartcam devices by sdb9696 · Pull Request #1370 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add bare bones homekit modules smart and smartcam devices 8000 #1370

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 5 commits into from
Dec 14, 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
1 change: 1 addition & 0 deletions kasa/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions kasa/smart/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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
Expand Down Expand Up @@ -67,5 +68,6 @@
"Thermostat",
"SmartLightEffect",
"OverheatProtection",
"HomeKit",
"Matter",
]
32 changes: 32 additions & 0 deletions kasa/smart/modules/homekit.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions kasa/smartcam/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand All @@ -17,5 +18,6 @@
"Led",
"PanTilt",
"Time",
"HomeKit",
"Matter",
]
16 changes: 16 additions & 0 deletions kasa/smartcam/modules/homekit.py
Original file line number Diff line number Diff line change
@@ -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 {}

Check warning on line 16 in kasa/smartcam/modules/homekit.py

View check run for this annotation

Codecov / codecov/patch

kasa/smartcam/modules/homekit.py#L16

Added line #L16 was not covered by tests
9 changes: 9 additions & 0 deletions tests/fakeprotocol_smart.py
B7B9
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ def credentials_hash(self):
"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},
Expand Down
16 changes: 16 additions & 0 deletions tests/smart/modules/test_homekit.py
Original file line number Diff line number Diff line change
@@ -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
Loading
0