mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-08 22:07:06 +00:00
Allow raw-command and wifi without update (#688)
* Allow raw-command and wifi without update * Call update always but on wifi&raw-command * Add tests * Skip update also if device_family was defined, as device factory performs an update
This commit is contained in:
parent
f045696ebe
commit
e576fcdb46
@ -317,7 +317,6 @@ async def cli(
|
|||||||
|
|
||||||
if type is not None:
|
if type is not None:
|
||||||
dev = TYPE_TO_CLASS[type](host)
|
dev = TYPE_TO_CLASS[type](host)
|
||||||
await dev.update()
|
|
||||||
elif device_family and encrypt_type:
|
elif device_family and encrypt_type:
|
||||||
ctype = ConnectionType(
|
ctype = ConnectionType(
|
||||||
DeviceFamilyType(device_family),
|
DeviceFamilyType(device_family),
|
||||||
@ -339,6 +338,9 @@ async def cli(
|
|||||||
port=port,
|
port=port,
|
||||||
credentials=credentials,
|
credentials=credentials,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Skip update for wifi & raw-command, and if factory was used to connect
|
||||||
|
if ctx.invoked_subcommand not in ["wifi", "raw-command"] and not device_family:
|
||||||
await dev.update()
|
await dev.update()
|
||||||
|
|
||||||
ctx.obj = dev
|
ctx.obj = dev
|
||||||
|
@ -34,6 +34,27 @@ from kasa.smartprotocol import SmartProtocol
|
|||||||
from .conftest import device_iot, device_smart, handle_turn_on, new_discovery, turn_on
|
from .conftest import device_iot, device_smart, handle_turn_on, new_discovery, turn_on
|
||||||
|
|
||||||
|
|
||||||
|
async def test_update_called_by_cli(dev, mocker):
|
||||||
|
"""Test that device update is called on main."""
|
||||||
|
runner = CliRunner()
|
||||||
|
update = mocker.patch.object(dev, "update")
|
||||||
|
mocker.patch("kasa.discover.Discover.discover_single", return_value=dev)
|
||||||
|
|
||||||
|
res = await runner.invoke(
|
||||||
|
cli,
|
||||||
|
[
|
||||||
|
"--host",
|
||||||
|
"127.0.0.1",
|
||||||
|
"--username",
|
||||||
|
"foo",
|
||||||
|
"--password",
|
||||||
|
"bar",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert res.exit_code == 0
|
||||||
|
update.assert_called()
|
||||||
|
|
||||||
|
|
||||||
@device_iot
|
@device_iot
|
||||||
async def test_sysinfo(dev):
|
async def test_sysinfo(dev):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
@ -86,8 +107,9 @@ async def test_alias(dev):
|
|||||||
await dev.set_alias(old_alias)
|
await dev.set_alias(old_alias)
|
||||||
|
|
||||||
|
|
||||||
async def test_raw_command(dev):
|
async def test_raw_command(dev, mocker):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
|
update = mocker.patch.object(dev, "update")
|
||||||
from kasa.tapo import TapoDevice
|
from kasa.tapo import TapoDevice
|
||||||
|
|
||||||
if isinstance(dev, TapoDevice):
|
if isinstance(dev, TapoDevice):
|
||||||
@ -96,6 +118,10 @@ async def test_raw_command(dev):
|
|||||||
params = ["system", "get_sysinfo"]
|
params = ["system", "get_sysinfo"]
|
||||||
res = await runner.invoke(raw_command, params, obj=dev)
|
res = await runner.invoke(raw_command, params, obj=dev)
|
||||||
|
|
||||||
|
# Make sure that update was not called for wifi
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
update.assert_called()
|
||||||
|
|
||||||
assert res.exit_code == 0
|
assert res.exit_code == 0
|
||||||
assert dev.model in res.output
|
assert dev.model in res.output
|
||||||
|
|
||||||
@ -129,14 +155,19 @@ async def test_wifi_scan(dev):
|
|||||||
|
|
||||||
|
|
||||||
@device_smart
|
@device_smart
|
||||||
async def test_wifi_join(dev):
|
async def test_wifi_join(dev, mocker):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
|
update = mocker.patch.object(dev, "update")
|
||||||
res = await runner.invoke(
|
res = await runner.invoke(
|
||||||
wifi,
|
wifi,
|
||||||
["join", "FOOBAR", "--keytype", "wpa_psk", "--password", "foobar"],
|
["join", "FOOBAR", "--keytype", "wpa_psk", "--password", "foobar"],
|
||||||
obj=dev,
|
obj=dev,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Make sure that update was not called for wifi
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
update.assert_called()
|
||||||
|
|
||||||
assert res.exit_code == 0
|
assert res.exit_code == 0
|
||||||
assert "Asking the device to connect to FOOBAR" in res.output
|
assert "Asking the device to connect to FOOBAR" in res.output
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user