mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-10-26 22:52:55 +00:00
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:
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user