mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-27 00:56:23 +00:00
Pass timeout parameters to discover_single (#744)
* Pass timeout parameters to discover_single * Fix tests
This commit is contained in:
parent
458949157a
commit
5d81e9f94c
@ -216,7 +216,7 @@ def json_formatter_cb(result, **kwargs):
|
|||||||
@click.option(
|
@click.option(
|
||||||
"--discovery-timeout",
|
"--discovery-timeout",
|
||||||
envvar="KASA_DISCOVERY_TIMEOUT",
|
envvar="KASA_DISCOVERY_TIMEOUT",
|
||||||
default=3,
|
default=5,
|
||||||
required=False,
|
required=False,
|
||||||
show_default=True,
|
show_default=True,
|
||||||
help="Timeout for discovery.",
|
help="Timeout for discovery.",
|
||||||
@ -348,11 +348,16 @@ async def cli(
|
|||||||
)
|
)
|
||||||
dev = await Device.connect(config=config)
|
dev = await Device.connect(config=config)
|
||||||
else:
|
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(
|
dev = await Discover.discover_single(
|
||||||
host,
|
host,
|
||||||
port=port,
|
port=port,
|
||||||
credentials=credentials,
|
credentials=credentials,
|
||||||
|
timeout=timeout,
|
||||||
|
discovery_timeout=discovery_timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Skip update on specific commands, or if device factory,
|
# Skip update on specific commands, or if device factory,
|
||||||
|
@ -7,6 +7,7 @@ from asyncclick.testing import CliRunner
|
|||||||
|
|
||||||
from kasa import (
|
from kasa import (
|
||||||
AuthenticationException,
|
AuthenticationException,
|
||||||
|
Credentials,
|
||||||
Device,
|
Device,
|
||||||
EmeterStatus,
|
EmeterStatus,
|
||||||
SmartDeviceException,
|
SmartDeviceException,
|
||||||
@ -341,7 +342,9 @@ async def test_credentials(discovery_mock, mocker):
|
|||||||
async def test_without_device_type(dev, mocker):
|
async def test_without_device_type(dev, mocker):
|
||||||
"""Test connecting without the device type."""
|
"""Test connecting without the device type."""
|
||||||
runner = CliRunner()
|
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(
|
res = await runner.invoke(
|
||||||
cli,
|
cli,
|
||||||
[
|
[
|
||||||
@ -351,9 +354,18 @@ async def test_without_device_type(dev, mocker):
|
|||||||
"foo",
|
"foo",
|
||||||
"--password",
|
"--password",
|
||||||
"bar",
|
"bar",
|
||||||
|
"--discovery-timeout",
|
||||||
|
"7",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
assert res.exit_code == 0
|
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"])
|
@pytest.mark.parametrize("auth_param", ["--username", "--password"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user