10000 Leverage data from UDP discovery to initialize device structure (#132) · python-kasa/python-kasa@d4a361d · GitHub
[go: up one dir, main page]

Skip to content

Commit d4a361d

Browse files
dlee1j1dlee1j1
andauthored
Leverage data from UDP discovery to initialize device structure (#132)
* avoid talking to devices after UDP discovery * formatting fix * more formatting * more formatting changes * undo gitignore changes * fixing git ignore for black Co-authored-by: dlee1j1 <dlee1j@yahoo.comm>
1 parent 98b40b5 commit d4a361d

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

kasa/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,12 @@ async def dump_discover(ctx, scrub):
174174
async def discover(ctx, timeout, discover_only, dump_raw):
175175
"""Discover devices in the network."""
176176
target = ctx.parent.params["target"]
177-
click.echo(f"Discovering devices for {timeout} seconds")
177+
click.echo(f"Discovering devices on {target} for {timeout} seconds")
178178
found_devs = await Discover.discover(
179179
target=target, timeout=timeout, return_raw=dump_raw
180180
)
181181
if not discover_only:
182182
for ip, dev in found_devs.items():
183-
await dev.update()
184183
if dump_raw:
185184
click.echo(dev)
186185
continue

kasa/discover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def datagram_received(self, data, addr) -> None:
7777

7878
device_class = Discover._get_device_class(info)
7979
device = device_class(ip)
80-
asyncio.ensure_future(device.update())
80+
device.update_from_discover_info(info)
8181

8282
self.discovered_devices[ip] = device
8383
self.discovered_devices_raw[ip] = info

kasa/smartdevice.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ async def update(self):
304304
# TODO: keep accessible for tests
305305
self._sys_info = self._last_update["system"]["get_sysinfo"]
306306

307+
def update_from_discover_info(self, info):
308+
"""Update state from info from the discover call."""
309+
self._last_update = info
310+
self._sys_info = info["system"]["get_sysinfo"]
311+
307312
@property # type: ignore
308313
@requires_update
309314
def sys_info(self) -> Dict[str, Any]:

0 commit comments

Comments
 (0)
0