mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Add common childsetup interface (#1470)
Add a common interface for the `childsetup` module across `smart` and `smartcam` hubs. Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
@@ -4,10 +4,10 @@ from pytest_mock import MockerFixture
|
||||
from kasa import DeviceType, Module
|
||||
from kasa.cli.hub import hub
|
||||
|
||||
from ..device_fixtures import HUBS_SMART, hubs_smart, parametrize, plug_iot
|
||||
from ..device_fixtures import hubs, plug_iot
|
||||
|
||||
|
||||
@hubs_smart
|
||||
@hubs
|
||||
async def test_hub_pair(dev, mocker: MockerFixture, runner, caplog):
|
||||
"""Test that pair calls the expected methods."""
|
||||
cs = dev.modules.get(Module.ChildSetup)
|
||||
@@ -25,7 +25,7 @@ async def test_hub_pair(dev, mocker: MockerFixture, runner, caplog):
|
||||
assert res.exit_code == 0
|
||||
|
||||
|
||||
@parametrize("hubs smart", model_filter=HUBS_SMART, protocol_filter={"SMART"})
|
||||
@hubs
|
||||
async def test_hub_unpair(dev, mocker: MockerFixture, runner):
|
||||
"""Test that unpair calls the expected method."""
|
||||
if not dev.children:
|
||||
|
@@ -346,6 +346,7 @@ hub_smartcam = parametrize(
|
||||
device_type_filter=[DeviceType.Hub],
|
||||
protocol_filter={"SMARTCAM"},
|
||||
)
|
||||
hubs = parametrize_combine([hubs_smart, hub_smartcam])
|
||||
doobell_smartcam = parametrize(
|
||||
"doorbell smartcam",
|
||||
device_type_filter=[DeviceType.Doorbell],
|
||||
|
@@ -176,10 +176,19 @@ class FakeSmartTransport(BaseTransport):
|
||||
"child_quick_setup",
|
||||
{"device_category_list": [{"category": "subg.trv"}]},
|
||||
),
|
||||
# no devices found
|
||||
"get_scan_child_device_list": (
|
||||
"child_quick_setup",
|
||||
{"child_device_list": [{"dummy": "response"}], "scan_status": "idle"},
|
||||
{
|
||||
"child_device_list": [
|
||||
{
|
||||
"device_id": "0000000000000000000000000000000000000000",
|
||||
"category": "subg.trigger.button",
|
||||
"device_model": "S200B",
|
||||
"name": "I01BU0tFRF9OQU1FIw==",
|
||||
}
|
||||
],
|
||||
"scan_status": "idle",
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,6 @@ async def test_childsetup_pair(
|
||||
mock_query_helper.assert_has_awaits(
|
||||
[
|
||||
mocker.call("begin_scanning_child_device", None),
|
||||
mocker.call("get_support_child_device_category", None),
|
||||
mocker.call("get_scan_child_device_list", params=mocker.ANY),
|
||||
mocker.call("add_child_device_list", params=mocker.ANY),
|
||||
]
|
||||
|
@@ -41,29 +41,11 @@ async def test_childsetup_pair(
|
||||
[
|
||||
mocker.call(
|
||||
"startScanChildDevice",
|
||||
params={
|
||||
"childControl": {
|
||||
"category": [
|
||||
"camera",
|
||||
"subg.trv",
|
||||
"subg.trigger",
|
||||
"subg.plugswitch",
|
||||
]
|
||||
}
|
||||
},
|
||||
params={"childControl": {"category": cs.supported_categories}},
|
||||
),
|
||||
mocker.call(
|
||||
"getScanChildDeviceList",
|
||||
{
|
||||
"childControl": {
|
||||
"category": [
|
||||
"camera",
|
||||
"subg.trv",
|
||||
"subg.trigger",
|
||||
"subg.plugswitch",
|
||||
]
|
||||
}
|
||||
},
|
||||
{"childControl": {"category": cs.supported_categories}},
|
||||
),
|
||||
mocker.call(
|
||||
"addScanChildDeviceList",
|
||||
@@ -71,10 +53,10 @@ async def test_childsetup_pair(
|
||||
"childControl": {
|
||||
"child_device_list": [
|
||||
{
|
||||
"device_id": "0000000000000000000000000000000000000000",
|
||||
"category": "subg.trigger.button",
|
||||
"device_model": "S200B",
|
||||
"name": "I01BU0tFRF9OQU1FIw====",
|
||||
"device_id": mocker.ANY,
|
||||
"category": mocker.ANY,
|
||||
"device_model": mocker.ANY,
|
||||
"name": mocker.ANY,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -148,6 +148,25 @@ def test_tutorial_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_childsetup_examples(readmes_mock, mocker):
|
||||
"""Test device examples."""
|
||||
pair_resp = [
|
||||
{
|
||||
"device_id": "SCRUBBED_CHILD_DEVICE_ID_5",
|
||||
"category": "subg.trigger.button",
|
||||
"device_model": "S200B",
|
||||
"name": "I01BU0tFRF9OQU1FIw====",
|
||||
}
|
||||
]
|
||||
mocker.patch(
|
||||
"kasa.smartcam.modules.childsetup.ChildSetup.pair", return_value=pair_resp
|
||||
)
|
||||
res = xdoctest.doctest_module("kasa.interfaces.childsetup", "all")
|
||||
assert res["n_passed"] > 0
|
||||
assert res["n_warned"] == 0
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def readmes_mock(mocker):
|
||||
fixture_infos = {
|
||||
@@ -156,6 +175,7 @@ async def readmes_mock(mocker):
|
||||
"127.0.0.3": get_fixture_info("L530E(EU)_3.0_1.1.6.json", "SMART"), # Bulb
|
||||
"127.0.0.4": get_fixture_info("KL430(US)_1.0_1.0.10.json", "IOT"), # Lightstrip
|
||||
"127.0.0.5": get_fixture_info("HS220(US)_1.0_1.5.7.json", "IOT"), # Dimmer
|
||||
"127.0.0.6": get_fixture_info("H200(US)_1.0_1.3.6.json", "SMARTCAM"), # Hub
|
||||
}
|
||||
fixture_infos["127.0.0.1"].data["system"]["get_sysinfo"]["alias"] = (
|
||||
"Bedroom Power Strip"
|
||||
@@ -176,4 +196,7 @@ async def readmes_mock(mocker):
|
||||
fixture_infos["127.0.0.5"].data["system"]["get_sysinfo"]["alias"] = (
|
||||
"Living Room Dimmer Switch"
|
||||
)
|
||||
fixture_infos["127.0.0.6"].data["getDeviceInfo"]["device_info"]["basic_info"][
|
||||
"device_alias"
|
||||
] = "Tapo Hub"
|
||||
return patch_discovery(fixture_infos, mocker)
|
||||
|
Reference in New Issue
Block a user