Add discovery timeout parameter (#486)

* Add discovery timeout parameter

* Rename variable to be more pythonic
This commit is contained in:
sdb9696 2023-08-03 13:24:46 +01:00 committed by GitHub
parent 176ced9e6e
commit 064e3fe560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,9 +129,16 @@ def json_formatter_cb(result, **kwargs):
@click.option(
"--json", default=False, is_flag=True, help="Output raw device response as JSON."
)
@click.option(
"--discovery-timeout",
envvar="KASA_DISCOVERY_TIMEOUT",
default=3,
required=False,
help="Timeout for discovery.",
)
@click.version_option(package_name="python-kasa")
@click.pass_context
async def cli(ctx, host, port, alias, target, debug, type, json):
async def cli(ctx, host, port, alias, target, debug, type, json, discovery_timeout):
"""A tool for controlling TP-Link smart home devices.""" # noqa
# no need to perform any checks if we are just displaying the help
if sys.argv[-1] == "--help":
@ -179,7 +186,7 @@ async def cli(ctx, host, port, alias, target, debug, type, json):
if host is None:
echo("No host name given, trying discovery..")
return await ctx.invoke(discover)
return await ctx.invoke(discover, timeout=discovery_timeout)
if type is not None:
dev = TYPE_TO_CLASS[type](host)