Add Device.supports_module() and stop querying HomeKit for iot devices (#1808)

Some legacy iot firmware stops responding when an unsupported module follows `system` in a request, which made every update time out once the HomeKit query was added.

This stops querying HomeKit in `update()` for IOT devices and adds `Device.supports_module()` API to allow checking if some module is supported by the device.
This commit is contained in:
Teemu R.
2026-10-24 16:22:33 +02:00
committed by GitHub
parent e29864bfdc
commit 30f5e4a1b9
6 changed files with 130 additions and 18 deletions

View File

@@ -11,6 +11,7 @@ from contextlib import AbstractContextManager, nullcontext
from unittest.mock import AsyncMock, patch
import pytest
from pytest_mock import MockerFixture
import kasa
from kasa import Credentials, Device, DeviceConfig, DeviceType, KasaException, Module
@@ -77,6 +78,16 @@ async def test_alias(dev: Device) -> None:
assert dev.alias == original
async def test_supports_module(dev: Device, mocker: MockerFixture) -> None:
"""Test modules of the device are supported without querying the device."""
spy = mocker.spy(dev.protocol, "query")
assert await dev.supports_module("not_a_module") is False
for name in dev.modules:
assert await dev.supports_module(name) is True
spy.assert_not_called()
@device_classes
async def test_device_class_ctors(device_class_name_obj) -> None:
"""Make sure constructor api not broken for new and existing SmartDevices."""