From bea87ce58e2e46e8798efe716c4a9538e74a64cc Mon Sep 17 00:00:00 2001 From: sdb9696 Date: Wed, 1 May 2024 10:59:10 +0100 Subject: [PATCH 1/2] Fix wifi scan re-querying error --- kasa/smart/smartdevice.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 04c2607be..430566010 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -512,22 +512,18 @@ def _net_for_scan_info(res): bssid=res["bssid"], ) - async def _query_networks(networks=None, start_index=0): - _LOGGER.debug("Querying networks using start_index=%s", start_index) + async def _query_networks(networks=None): + _LOGGER.debug("Querying networks") if networks is None: networks = [] resp = await self.protocol.query( - {"get_wireless_scan_info": {"start_index": start_index}} + {"get_wireless_scan_info": {"start_index": 0}} ) - network_list = [ + networks = [ _net_for_scan_info(net) for net in resp["get_wireless_scan_info"]["ap_list"] ] - networks.extend(network_list) - - if resp["get_wireless_scan_info"].get("sum", 0) > start_index + 10: - return await _query_networks(networks, start_index=start_index + 10) return networks From 61adb3c68900a835b9d31fd0f1a054c9cf0b16c2 Mon Sep 17 00:00:00 2001 From: sdb9696 Date: Wed, 1 May 2024 14:57:57 +0100 Subject: [PATCH 2/2] Remove recursive sub function --- kasa/smart/smartdevice.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 430566010..7ee5ab0f2 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -512,22 +512,13 @@ def _net_for_scan_info(res): bssid=res["bssid"], ) - async def _query_networks(networks=None): - _LOGGER.debug("Querying networks") - if networks is None: - networks = [] + _LOGGER.debug("Querying networks") - resp = await self.protocol.query( - {"get_wireless_scan_info": {"start_index": 0}} - ) - networks = [ - _net_for_scan_info(net) - for net in resp["get_wireless_scan_info"]["ap_list"] - ] - - return networks - - return await _query_networks() + resp = await self.protocol.query({"get_wireless_scan_info": {"start_index": 0}}) + networks = [ + _net_for_scan_info(net) for net in resp["get_wireless_scan_info"]["ap_list"] + ] + return networks async def wifi_join(self, ssid: str, password: str, keytype: str = "wpa2_psk"): """Join the given wifi network.