8000 Cleanup cli discover · python-kasa/python-kasa@01d4ed2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01d4ed2

Browse files
committed
Cleanup cli discover
* Use on_discovered for smoother user experience * Remove --discover-only as unnecessary
1 parent c865d3f commit 01d4ed2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

kasa/cli.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""python-kasa cli tool."""
2+
import asyncio
23
import logging
34
from pprint import pformat as pf
45
from typing import cast
@@ -145,24 +146,24 @@ async def join(dev: SmartDevice, ssid, password, keytype):
145146

146147
@cli.command()
147148
@click.option("--timeout", default=3, required=False)
148-
@click.option("--discover-only", default=False)
149149
@click.option("--dump-raw", is_flag=True)
150150
@click.pass_context
151-
async def discover(ctx, timeout, discover_only, dump_raw):
151+
async def discover(ctx, timeout, dump_raw):
152152
"""Discover devices in the network."""
153153
target = ctx.parent.params["target"]
154154
click.echo(f"Discovering devices on {target} for {timeout} seconds")
155-
found_devs = await Discover.discover(target=target, timeout=timeout)
156-
if not discover_only:
157-
for ip, dev in found_devs.items():
158-
if dump_raw:
159-
click.echo(dev.sys_info)
160-
continue
155+
sem = asyncio.Semaphore()
156+
157+
async def print_discovered(dev: SmartDevice):
158+
await dev.update()
159+
async with sem:
161160
ctx.obj = dev
162161
await ctx.invoke(state)
163162
click.echo()
164163

165-
return found_devs
164+
await Discover.discover(
165+
target=target, timeout=timeout, on_discovered=print_discovered
166+
)
166167

167168

168169
async def find_host_from_alias(alias, target="255.255.255.255", timeout=1, attempts=3):
@@ -224,7 +225,6 @@ async def state(ctx, dev: SmartDevice):
224225
click.echo(click.style("\n\t== Device specific information ==", bold=True))
225226
for k, v in dev.state_information.items():
226227
click.echo(f"\t{k}: {v}")
227-
click.echo()
228228

229229
if dev.has_emeter:
230230
click.echo(click.style("\n\t== Current State ==", bold=True))

0 commit comments

Comments
 (0)
0