Add bare bones homekit module for iot devices (#1566)

Based on the existing smart HomeKit module, this has been tested with a real device that supports this module.


---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
This commit is contained in:
ZeliardM
2025-10-10 10:45:16 -04:00
committed by GitHub
parent 2b881cfd7b
commit 0f6fc9c4d1
13 changed files with 221 additions and 5 deletions

View File

@@ -73,6 +73,7 @@ PLUGS_IOT = {
"HS105",
"HS110",
"EP10",
"EP25",
"KP100",
"KP105",
"KP115",
@@ -139,7 +140,7 @@ THERMOSTATS_SMART = {"KE100"}
VACUUMS_SMART = {"RV20"}
WITH_EMETER_IOT = {"HS110", "HS300", "KP115", "KP125", *BULBS_IOT}
WITH_EMETER_IOT = {"EP25", "HS110", "HS300", "KP115", "KP125", *BULBS_IOT}
WITH_EMETER_SMART = {"P110", "P110M", "P115", "KP125M", "EP25", "P304M"}
WITH_EMETER = {*WITH_EMETER_IOT, *WITH_EMETER_SMART}

View File

@@ -0,0 +1,80 @@
{
"cnCloud": {
"get_info": {
"binded": 1,
"cld_connection": 1,
"err_code": 0,
"fwDlPage": "",
"fwNotifyType": -1,
"illegalType": 0,
"server": "n-devs.tplinkcloud.com",
"stopConnect": 0,
"tcspInfo": "",
"tcspStatus": 1,
"username": "user@example.com"
},
"get_intl_fw_list": {
"err_code": 0,
"fw_list": []
}
},
"emeter": {
"get_realtime": {
"current_ma": 0,
"err_code": 0,
"power_mw": 0,
"total_wh": 50,
"voltage_mv": 125403
}
},
"schedule": {
"get_next_action": {
"err_code": 0,
"type": -1
},
"get_rules": {
"enable": 0,
"err_code": 0,
"rule_list": [],
"version": 2
}
},
"smartlife.iot.homekit": {
"setup_info_get": {
"err_code": 0,
"setup_code": "000-00-000",
"setup_payload": "0-00://0000000000000"
}
},
"system": {
"get_sysinfo": {
"active_mode": "none",
"alias": "#MASKED_NAME#",
"dev_name": "Smart Wi-Fi Plug Mini",
"deviceId": "0000000000000000000000000000000000000000",
"err_code": 0,
"feature": "TIM:ENE",
"hwId": "00000000000000000000000000000000",
"hw_ver": "1.0",
"icon_hash": "",
"latitude_i": 0,
"led_off": 0,
"longitude_i": 0,
"mac": "AC:15:A2:00:00:00",
"mic_type": "IOT.SMARTPLUGSWITCH",
"model": "EP25(US)",
"next_action": {
"type": -1
},
"ntc_state": 0,
"obd_src": "apple",
"oemId": "00000000000000000000000000000000",
"on_time": 495961,
"relay_state": 1,
"rssi": -37,
"status": "configured",
"sw_ver": "1.0.14 Build 240424 Rel.094105",
"updating": 0
}
}
}

View File

@@ -0,0 +1,59 @@
from unittest.mock import PropertyMock, patch
import pytest
from kasa import Module
from kasa.iot import IotDevice
from kasa.iot.modules.homekit import HomeKit
from ...device_fixtures import device_iot
@device_iot
def test_homekit_getters(dev: IotDevice):
# HomeKit can be present on any IOT device
if Module.IotHomeKit not in dev.modules:
pytest.skip("HomeKit module not present on this device")
homekit: HomeKit = dev.modules[Module.IotHomeKit]
info = homekit.info
if not info:
pytest.skip("No HomeKit data present for this fixture")
assert "setup_code" in info
assert "setup_payload" in info
assert "err_code" in info
# Check that the setup_code and setup_payload are strings
assert isinstance(info["setup_code"], str)
assert isinstance(info["setup_payload"], str)
assert isinstance(info["err_code"], int)
# Check that the HomeKit module properties match
assert info["setup_code"] == homekit.setup_code
assert info["setup_payload"] == homekit.setup_payload
@device_iot
def test_homekit_feature(dev: IotDevice):
if Module.IotHomeKit not in dev.modules:
pytest.skip("HomeKit module not present on this device")
homekit: HomeKit = dev.modules[Module.IotHomeKit]
if not homekit.info:
pytest.skip("No HomeKit data present for this device")
feature = homekit._all_features.get("homekit_setup_code")
assert feature is not None
assert isinstance(feature.attribute_getter, str)
value = getattr(homekit, feature.attribute_getter)
assert value == homekit.setup_code
@device_iot
def test_initialize_features_skips_when_no_data(dev: IotDevice):
if Module.IotHomeKit not in dev.modules:
pytest.skip("HomeKit module not present on this device")
homekit: HomeKit = dev.modules[Module.IotHomeKit]
if "homekit_setup_code" in homekit._all_features:
pytest.skip("HomeKit feature already present on this device")
# Patch .data so it looks like no homekit data is present
with patch.object(HomeKit, "data", new_callable=PropertyMock) as mock_data:
mock_data.return_value = {}
homekit._initialize_features()
# Since there was no data, no features should be added
assert "homekit_setup_code" not in homekit._all_features