mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 16:46:23 +00:00
Add discovery timeout parameter (#486)
* Add discovery timeout parameter * Rename variable to be more pythonic
This commit is contained in:
parent
176ced9e6e
commit
064e3fe560
11
kasa/cli.py
11
kasa/cli.py
@ -129,9 +129,16 @@ def json_formatter_cb(result, **kwargs):
|
|||||||
@click.option(
|
@click.option(
|
||||||
"--json", default=False, is_flag=True, help="Output raw device response as JSON."
|
"--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.version_option(package_name="python-kasa")
|
||||||
@click.pass_context
|
@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
|
"""A tool for controlling TP-Link smart home devices.""" # noqa
|
||||||
# no need to perform any checks if we are just displaying the help
|
# no need to perform any checks if we are just displaying the help
|
||||||
if sys.argv[-1] == "--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:
|
if host is None:
|
||||||
echo("No host name given, trying discovery..")
|
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:
|
if type is not None:
|
||||||
dev = TYPE_TO_CLASS[type](host)
|
dev = TYPE_TO_CLASS[type](host)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user