FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Pass timeout parameters to discover_single by sdb9696 · Pull Request #744 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 7 additions & 2 deletions kasa/cli.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _device_to_serializable(val: Device):
@click.option(
"--discovery-timeout",
envvar="KASA_DISCOVERY_TIMEOUT",
default=3,
default=5,
required=False,
show_default=True,
help="Timeout for discovery.",
Expand Down Expand Up @@ -348,11 +348,16 @@ def _nop_echo(*args, **kwargs):
)
dev = await Device.connect(config=config)
else:
echo("No --type or --device-family and --encrypt-type defined, discovering..")
echo(
"No --type or --device-family and --encrypt-type defined, "
+ f"discovering for {discovery_timeout} seconds.."
)
dev = await Discover.discover_single(
host,
port=port,
credentials=credentials,
timeout=timeout,
discovery_timeout=discovery_timeout,
)

# Skip update on specific commands, or if device factory,
Expand Down
14 changes: 13 additions & 1 deletion kasa/tests/test_cli.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from kasa import (
AuthenticationException,
Credentials,
Device,
EmeterStatus,
SmartDeviceException,
Expand Down Expand Up @@ -341,7 +342,9 @@ async def _state(dev: Device):
async def test_without_device_type(dev, mocker):
"""Test connecting without the device type."""
runner = CliRunner()
mocker.patch("kasa.discover.Discover.discover_single", return_value=dev)
discovery_mock = mocker.patch(
"kasa.discover.Discover.discover_single", return_value=dev
)
res = await runner.invoke(
cli,
[
Expand All @@ -351,9 +354,18 @@ async def test_without_device_type(dev, mocker):
"foo",
"--password",
"bar",
"--discovery-timeout",
"7",
],
)
assert res.exit_code == 0
discovery_mock.assert_called_once_with(
"127.0.0.1",
port=None,
credentials=Credentials("foo", "bar"),
timeout=5,
discovery_timeout=7,
)


@pytest.mark.parametrize("auth_param", ["--username", "--password"])
Expand Down

Back | FazBrowse Home | New Git URL