Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow sub-command invocation on discovered devices #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions kasa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def cli(ctx, host, alias, target, debug, type):

if host is None:
click.echo("No host name given, trying discovery..")
await ctx.invoke(discover)
await ctx.invoke(discover, target=target, command=ctx.invoked_subcommand)
return

if type is not None:
Expand Down Expand Up @@ -141,18 +141,22 @@ async def join(dev: SmartDevice, ssid, password, keytype):

@cli.command()
@click.option("--timeout", default=3, required=False)
@click.option("--target", default="255.255.255.255", required=False)
@click.argument("command", required=False)
@click.pass_context
async def discover(ctx, timeout):
async def discover(ctx, timeout, target, command):
"""Discover devices in the network."""
target = ctx.parent.params["target"]
target = target or ctx.parent.params["target"]
click.echo(f"Discovering devices on {target} for {timeout} seconds")
sem = asyncio.Semaphore()

async def print_discovered(dev: SmartDevice):
await dev.update()
async with sem:
await dev.update()
ctx.obj = dev
await ctx.invoke(state)
cmd = command or "state"
click.echo(f"Calling {cmd} for {dev}")
await ctx.invoke(globals()[cmd])
click.echo()

await Discover.discover(
Expand Down