From faf90dde6441a089eb8c4e2dc3aa4f1331e28b5a Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:16:09 +0000 Subject: [PATCH] Fix cli discover config --- kasa/cli/discover.py | 7 +++++-- kasa/discover.py | 1 + tests/test_cli.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kasa/cli/discover.py b/kasa/cli/discover.py index 07500f3b..af367e32 100644 --- a/kasa/cli/discover.py +++ b/kasa/cli/discover.py @@ -261,8 +261,11 @@ async def config(ctx: click.Context) -> DeviceDict: host_port = host + (f":{port}" if port else "") def on_attempt(connect_attempt: ConnectAttempt, success: bool) -> None: - prot, tran, dev = connect_attempt - key_str = f"{prot.__name__} + {tran.__name__} + {dev.__name__}" + prot, tran, dev, https = connect_attempt + key_str = ( + f"{prot.__name__} + {tran.__name__} + {dev.__name__}" + f" + {'https' if https else 'http'}" + ) result = "succeeded" if success else "failed" msg = f"Attempt to connect to {host_port} with {key_str} {result}" echo(msg) diff --git a/kasa/discover.py b/kasa/discover.py index bfdb5fa8..36d6f277 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -146,6 +146,7 @@ class ConnectAttempt(NamedTuple): protocol: type transport: type device: type + https: bool class DiscoveredMeta(TypedDict): diff --git a/tests/test_cli.py b/tests/test_cli.py index 2f907502..19958d55 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1308,11 +1308,11 @@ async def test_discover_config(dev: Device, mocker, runner): expected = f"--device-family {cparam.device_family.value} --encrypt-type {cparam.encryption_type.value} {'--https' if cparam.https else '--no-https'}" assert expected in res.output assert re.search( - r"Attempt to connect to 127\.0\.0\.1 with \w+ \+ \w+ \+ \w+ failed", + r"Attempt to connect to 127\.0\.0\.1 with \w+ \+ \w+ \+ \w+ \+ \w+ failed", res.output.replace("\n", ""), ) assert re.search( - r"Attempt to connect to 127\.0\.0\.1 with \w+ \+ \w+ \+ \w+ succeeded", + r"Attempt to connect to 127\.0\.0\.1 with \w+ \+ \w+ \+ \w+ \+ \w+ succeeded", res.output.replace("\n", ""), )