mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-06 12:57:07 +00:00
Fix to call update when only --device-family passed to cli (#987)
This commit is contained in:
parent
0d84d8785e
commit
f3fe1bc3f4
19
kasa/cli.py
19
kasa/cli.py
@ -379,6 +379,7 @@ async def cli(
|
|||||||
echo("No host name given, trying discovery..")
|
echo("No host name given, trying discovery..")
|
||||||
return await ctx.invoke(discover)
|
return await ctx.invoke(discover)
|
||||||
|
|
||||||
|
device_updated = False
|
||||||
if type is not None:
|
if type is not None:
|
||||||
dev = TYPE_TO_CLASS[type](host)
|
dev = TYPE_TO_CLASS[type](host)
|
||||||
elif device_family and encrypt_type:
|
elif device_family and encrypt_type:
|
||||||
@ -396,11 +397,19 @@ async def cli(
|
|||||||
connection_type=ctype,
|
connection_type=ctype,
|
||||||
)
|
)
|
||||||
dev = await Device.connect(config=config)
|
dev = await Device.connect(config=config)
|
||||||
|
device_updated = True
|
||||||
else:
|
else:
|
||||||
echo(
|
if device_family or encrypt_type:
|
||||||
"No --type or --device-family and --encrypt-type defined, "
|
echo(
|
||||||
+ f"discovering for {discovery_timeout} seconds.."
|
"--device-family and --encrypt-type options must both be "
|
||||||
)
|
"provided or they are ignored\n"
|
||||||
|
f"discovering for {discovery_timeout} seconds.."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
echo(
|
||||||
|
"No --type or --device-family and --encrypt-type defined, "
|
||||||
|
+ f"discovering for {discovery_timeout} seconds.."
|
||||||
|
)
|
||||||
dev = await Discover.discover_single(
|
dev = await Discover.discover_single(
|
||||||
host,
|
host,
|
||||||
port=port,
|
port=port,
|
||||||
@ -411,7 +420,7 @@ async def cli(
|
|||||||
|
|
||||||
# Skip update on specific commands, or if device factory,
|
# Skip update on specific commands, or if device factory,
|
||||||
# that performs an update was used for the device.
|
# that performs an update was used for the device.
|
||||||
if ctx.invoked_subcommand not in SKIP_UPDATE_COMMANDS and not device_family:
|
if ctx.invoked_subcommand not in SKIP_UPDATE_COMMANDS and not device_updated:
|
||||||
await dev.update()
|
await dev.update()
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
|
@ -57,7 +57,15 @@ def runner():
|
|||||||
return runner
|
return runner
|
||||||
|
|
||||||
|
|
||||||
async def test_update_called_by_cli(dev, mocker, runner):
|
@pytest.mark.parametrize(
|
||||||
|
("device_family", "encrypt_type"),
|
||||||
|
[
|
||||||
|
pytest.param(None, None, id="No connect params"),
|
||||||
|
pytest.param("SMART.TAPOPLUG", None, id="Only device_family"),
|
||||||
|
pytest.param(None, "KLAP", id="Only encrypt_type"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_update_called_by_cli(dev, mocker, runner, device_family, encrypt_type):
|
||||||
"""Test that device update is called on main."""
|
"""Test that device update is called on main."""
|
||||||
update = mocker.patch.object(dev, "update")
|
update = mocker.patch.object(dev, "update")
|
||||||
|
|
||||||
@ -76,6 +84,10 @@ async def test_update_called_by_cli(dev, mocker, runner):
|
|||||||
"foo",
|
"foo",
|
||||||
"--password",
|
"--password",
|
||||||
"bar",
|
"bar",
|
||||||
|
"--device-family",
|
||||||
|
device_family,
|
||||||
|
"--encrypt-type",
|
||||||
|
encrypt_type,
|
||||||
],
|
],
|
||||||
catch_exceptions=False,
|
catch_exceptions=False,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user