mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 18:54:08 +00:00
Put modules back on children for wall switches (#881)
Puts modules back on the children for `WallSwitches` (i.e. ks240) and makes them accessible from the `modules` property on the parent.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from typing import cast
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from kasa import SmartDevice
|
||||
from kasa.smart.modules import FanModule
|
||||
from kasa.tests.device_fixtures import parametrize
|
||||
|
||||
fan = parametrize("has fan", component_filter="fan_control", protocol_filter={"SMART"})
|
||||
@@ -9,7 +12,7 @@ fan = parametrize("has fan", component_filter="fan_control", protocol_filter={"S
|
||||
@fan
|
||||
async def test_fan_speed(dev: SmartDevice, mocker: MockerFixture):
|
||||
"""Test fan speed feature."""
|
||||
fan = dev.modules.get("FanModule")
|
||||
fan = cast(FanModule, dev.modules.get("FanModule"))
|
||||
assert fan
|
||||
|
||||
level_feature = fan._module_features["fan_speed_level"]
|
||||
@@ -32,7 +35,7 @@ async def test_fan_speed(dev: SmartDevice, mocker: MockerFixture):
|
||||
@fan
|
||||
async def test_sleep_mode(dev: SmartDevice, mocker: MockerFixture):
|
||||
"""Test sleep mode feature."""
|
||||
fan = dev.modules.get("FanModule")
|
||||
fan = cast(FanModule, dev.modules.get("FanModule"))
|
||||
assert fan
|
||||
sleep_feature = fan._module_features["fan_sleep_mode"]
|
||||
assert isinstance(sleep_feature.value, bool)
|
||||
|
@@ -103,22 +103,22 @@ async def test_negotiate(dev: SmartDevice, mocker: MockerFixture):
|
||||
async def test_update_module_queries(dev: SmartDevice, mocker: MockerFixture):
|
||||
"""Test that the regular update uses queries from all supported modules."""
|
||||
# We need to have some modules initialized by now
|
||||
assert dev.modules
|
||||
assert dev._modules
|
||||
|
||||
device_queries: dict[SmartDevice, dict[str, Any]] = {}
|
||||
for mod in dev.modules.values():
|
||||
for mod in dev._modules.values():
|
||||
device_queries.setdefault(mod._device, {}).update(mod.query())
|
||||
|
||||
spies = {}
|
||||
for dev in device_queries:
|
||||
spies[dev] = mocker.spy(dev.protocol, "query")
|
||||
for device in device_queries:
|
||||
spies[device] = mocker.spy(device.protocol, "query")
|
||||
|
||||
await dev.update()
|
||||
for dev in device_queries:
|
||||
if device_queries[dev]:
|
||||
spies[dev].assert_called_with(device_queries[dev])
|
||||
for device in device_queries:
|
||||
if device_queries[device]:
|
||||
spies[device].assert_called_with(device_queries[device])
|
||||
else:
|
||||
spies[dev].assert_not_called()
|
||||
spies[device].assert_not_called()
|
||||
|
||||
|
||||
@bulb_smart
|
||||
|
Reference in New Issue
Block a user