From 47525c45efa249a0cfa0e23bb49db46a0ba8982d Mon Sep 17 00:00:00 2001 From: dlee1j1 Date: Wed, 3 Feb 2021 23:55:37 -0800 Subject: [PATCH 1/6] avoid talking to devices after UDP discovery --- .gitignore | 1 + kasa/cli.py | 3 +-- kasa/discover.py | 2 +- kasa/smartdevice.py | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9da1e2353..ace1570f7 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ venv .venv /build +kasa/launch.json diff --git a/kasa/cli.py b/kasa/cli.py index 167179e36..5efd6be6d 100755 --- a/kasa/cli.py +++ b/kasa/cli.py @@ -174,13 +174,12 @@ async def dump_discover(ctx, scrub): async def discover(ctx, timeout, discover_only, dump_raw): """Discover devices in the network.""" target = ctx.parent.params["target"] - click.echo(f"Discovering devices for {timeout} seconds") + click.echo(f"Discovering devices on {target} for {timeout} seconds") found_devs = await Discover.discover( target=target, timeout=timeout, return_raw=dump_raw ) if not discover_only: for ip, dev in found_devs.items(): - await dev.update() if dump_raw: click.echo(dev) continue diff --git a/kasa/discover.py b/kasa/discover.py index e4091512e..3e7f70207 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -77,7 +77,7 @@ def datagram_received(self, data, addr) -> None: device_class = Discover._get_device_class(info) device = device_class(ip) - asyncio.ensure_future(device.update()) + device.update_from_discover_info(info) self.discovered_devices[ip] = device self.discovered_devices_raw[ip] = info diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 19589bbad..0077e8098 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -304,6 +304,11 @@ async def update(self): # TODO: keep accessible for tests self._sys_info = self._last_update["system"]["get_sysinfo"] + def update_from_discover_info(self,info): + """Update state from info from the discover call""" + self._last_update = info + self._sys_info = info["system"]["get_sysinfo"] + @property # type: ignore @requires_update def sys_info(self) -> Dict[str, Any]: From 68984537e95db98a61af6dc53222d9a1cef3882c Mon Sep 17 00:00:00 2001 From: dlee1j1 Date: Fri, 5 Feb 2021 00:03:49 -0800 Subject: [PATCH 2/6] formatting fix --- kasa/smartdevice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 0077e8098..50b4baba7 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -304,7 +304,7 @@ async def update(self): # TODO: keep accessible for tests self._sys_info = self._last_update["system"]["get_sysinfo"] - def update_from_discover_info(self,info): + def update_from_discover_info(self, info): """Update state from info from the discover call""" self._last_update = info self._sys_info = info["system"]["get_sysinfo"] From 339b0dbb1912b427944c09ac10eba8863b1242fd Mon Sep 17 00:00:00 2001 From: dlee1j1 Date: Fri, 5 Feb 2021 00:50:57 -0800 Subject: [PATCH 3/6] more formatting --- kasa/smartdevice.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 50b4baba7..e19e796c9 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -305,7 +305,8 @@ async def update(self): self._sys_info = self._last_update["system"]["get_sysinfo"] def update_from_discover_info(self, info): - """Update state from info from the discover call""" + """Update state from info from the discover call. + """ self._last_update = info self._sys_info = info["system"]["get_sysinfo"] From 4e1b1b1cc005d1f64ce594ac2e5f02e59cb17423 Mon Sep 17 00:00:00 2001 From: dlee1j1 Date: Fri, 5 Feb 2021 00:53:40 -0800 Subject: [PATCH 4/6] more formatting changes --- kasa/smartdevice.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index e19e796c9..da5c0f65a 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -305,8 +305,7 @@ async def update(self): self._sys_info = self._last_update["system"]["get_sysinfo"] def update_from_discover_info(self, info): - """Update state from info from the discover call. - """ + """Update state from info from the discover call.""" self._last_update = info self._sys_info = info["system"]["get_sysinfo"] From 285a3be2d1bead23181cd02338ddf6a0fb4490d4 Mon Sep 17 00:00:00 2001 From: dlee1j1 Date: Fri, 5 Feb 2021 08:19:45 -0800 Subject: [PATCH 5/6] undo gitignore changes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ace1570f7..c3d669723 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ venv .venv /build -kasa/launch.json + From a38bb5bb7af1274a7d9747151a362166bc978613 Mon Sep 17 00:00:00 2001 From: dlee1j1 Date: Fri, 5 Feb 2021 08:26:08 -0800 Subject: [PATCH 6/6] fixing git ignore for black --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c3d669723..9da1e2353 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,3 @@ venv .venv /build -