mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-01-11 22:32:43 +00:00
Merge branch 'master' into feat/improve_alarm
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],
|
||||
|
||||
@@ -308,10 +308,6 @@ class FakeIotTransport(BaseTransport):
|
||||
child_ids = []
|
||||
_LOGGER.debug("Setting relay state to %s", x["state"])
|
||||
|
||||
if not child_ids and "children" in self.proto["system"]["get_sysinfo"]:
|
||||
for child in self.proto["system"]["get_sysinfo"]["children"]:
|
||||
child_ids.append(child["id"])
|
||||
|
||||
_LOGGER.info("child_ids: %s", child_ids)
|
||||
if child_ids:
|
||||
for child in self.proto["system"]["get_sysinfo"]["children"]:
|
||||
|
||||
@@ -174,10 +174,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",
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -137,8 +137,9 @@ async def test_query_helper(dev):
|
||||
@device_iot
|
||||
@turn_on
|
||||
async def test_state(dev, turn_on):
|
||||
await handle_turn_on(dev, turn_on)
|
||||
orig_state = dev.is_on
|
||||
await handle_turn_on(dev, turn_on)
|
||||
await dev.update()
|
||||
if orig_state:
|
||||
await dev.turn_off()
|
||||
await dev.update()
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from kasa import Device, Feature, KasaException
|
||||
from kasa.iot import IotStrip
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -168,7 +169,10 @@ async def test_feature_setters(dev: Device, mocker: MockerFixture):
|
||||
if feat.attribute_setter is None:
|
||||
return
|
||||
|
||||
expecting_call = feat.id not in internal_setters
|
||||
# IotStrip makes calls via it's children
|
||||
expecting_call = feat.id not in internal_setters and not isinstance(
|
||||
dev, IotStrip
|
||||
)
|
||||
|
||||
if feat.type == Feature.Type.Number:
|
||||
await feat.set_value(feat.minimum_value)
|
||||
|
||||
@@ -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