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

Allow sub-command invocation on discovered devices by rytilahti · Pull Request #392 · python-kasa/python-kasa · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) 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
14 changes: 9 additions & 5 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 @@ -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

Back | FazBrowse Home | New Git URL