mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-19 13:58:03 +00:00
Generalize smartdevice child support (#775)
* Initialize children's modules (and features) using the child component negotiation results * Set device_type based on the device response * Print out child features in cli 'state' * Add --child option to cli 'command' to allow targeting child devices * Guard "generic" features like rssi, ssid, etc. only to devices which have this information Note, we do not currently perform queries on child modules so some data may not be available. At the moment, a stop-gap solution to use parent's data is used but this is not always correct; even if the device shares the same clock and cloud connectivity, it may have its own firmware updates.
This commit is contained in:
@@ -19,6 +19,7 @@ from kasa.cli import (
|
||||
alias,
|
||||
brightness,
|
||||
cli,
|
||||
cmd_command,
|
||||
emeter,
|
||||
raw_command,
|
||||
reboot,
|
||||
@@ -136,6 +137,32 @@ async def test_raw_command(dev, mocker):
|
||||
assert "Usage" in res.output
|
||||
|
||||
|
||||
async def test_command_with_child(dev, mocker):
|
||||
"""Test 'command' command with --child."""
|
||||
runner = CliRunner()
|
||||
update_mock = mocker.patch.object(dev, "update")
|
||||
|
||||
dummy_child = mocker.create_autospec(IotDevice)
|
||||
query_mock = mocker.patch.object(
|
||||
dummy_child, "_query_helper", return_value={"dummy": "response"}
|
||||
)
|
||||
|
||||
mocker.patch.object(dev, "_children", {"XYZ": dummy_child})
|
||||
mocker.patch.object(dev, "get_child_device", return_value=dummy_child)
|
||||
|
||||
res = await runner.invoke(
|
||||
cmd_command,
|
||||
["--child", "XYZ", "command", "'params'"],
|
||||
obj=dev,
|
||||
catch_exceptions=False,
|
||||
)
|
||||
|
||||
update_mock.assert_called()
|
||||
query_mock.assert_called()
|
||||
assert '{"dummy": "response"}' in res.output
|
||||
assert res.exit_code == 0
|
||||
|
||||
|
||||
@device_smart
|
||||
async def test_reboot(dev, mocker):
|
||||
"""Test that reboot works on SMART devices."""
|
||||
|
Reference in New Issue
Block a user