8000 Fix to call update when only --device-family passed to cli by sdb9696 · Pull Request #987 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Fix to call update when only --device-family passed to cli #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
8000 Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions kasa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def _nop_echo(*args, **kwargs):
echo("No host name given, trying discovery..")
return await ctx.invoke(discover)

device_updated = False
if type is not None:
dev = TYPE_TO_CLASS[type](host)
elif device_family and encrypt_type:
Expand All @@ -396,11 +397,19 @@ def _nop_echo(*args, **kwargs):
connection_type=ctype,
)
dev = await Device.connect(config=config)
device_updated = True
else:
echo(
"No --type or --device-family and --encrypt-type defined, "
+ f"discovering for {discovery_timeout} seconds.."
)
if device_family or encrypt_type:
echo(
"--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(
host,
port=port,
Expand All @@ -411,7 +420,7 @@ def _nop_echo(*args, **kwargs):

# Skip update on specific commands, or if device factory,
# 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()

@asynccontextmanager
Expand Down
14 changes: 13 additions & 1 deletion kasa/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ def 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."""
update = mocker.patch.object(dev, "update")

Expand All @@ -76,6 +84,10 @@ async def test_update_called_by_cli(dev, mocker, runner):
"foo",
"--password",
"bar",
"--device-family",
device_family,
"--encrypt-type",
encrypt_type,
],
catch_exceptions=False,
)
Expand Down
Loading
0