From fae19a836c271ccd45e1e2b8a2de3b5c376e663a Mon Sep 17 00:00:00 2001 From: Thorsten Meinl Date: Fri, 22 Mar 2024 20:22:17 +0100 Subject: [PATCH 1/2] Update internal mower state upon update message This fixes issue #196. --- pyworxcloud/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyworxcloud/__init__.py b/pyworxcloud/__init__.py index 65ddf2b..1c20190 100644 --- a/pyworxcloud/__init__.py +++ b/pyworxcloud/__init__.py @@ -417,7 +417,9 @@ def _decode_data(self, device: DeviceHandler) -> None: logger.debug("No valid data was found, skipping update for %s", device.name) return + mower = device._mower if "dat" in data: + mower["last_status"]["payload"]["dat"] = data["dat"] if "uuid" in data["dat"]: device.uuid = data["dat"]["uuid"] @@ -444,6 +446,7 @@ def _decode_data(self, device: DeviceHandler) -> None: # Get device lock state device.locked = bool(data["dat"]["lk"]) if "lk" in data["dat"] else None + mower["locked"] = device.locked # Get battery info if available if "bt" in data["dat"]: @@ -480,6 +483,7 @@ def _decode_data(self, device: DeviceHandler) -> None: invalid_data = True if "cfg" in data: + mower["last_status"]["payload"]["cfg"] = data["cfg"] # try: if "dt" in data["cfg"]: dt_split = data["cfg"]["dt"].split("/") @@ -665,6 +669,8 @@ def _decode_data(self, device: DeviceHandler) -> None: device.name, device, device.time_zone, callback=self.update_attribute ) + mower["last_status"]["timestamp"] = device.updated + device.is_decoded = True logger.debug("Data for %s was decoded", device.name) From d789a113ebf83300549a6be04aa603c2a60320ca Mon Sep 17 00:00:00 2001 From: Thorsten Meinl Date: Fri, 22 Mar 2024 19:21:56 +0100 Subject: [PATCH 2/2] Optimized computation of zones array The previous approach had quadratic complexity, the new one is linear. --- pyworxcloud/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pyworxcloud/__init__.py b/pyworxcloud/__init__.py index 1c20190..eeec2ae 100644 --- a/pyworxcloud/__init__.py +++ b/pyworxcloud/__init__.py @@ -911,15 +911,15 @@ def setzone(self, serial_number: str, zone: str | int) -> None: "Cannot request this zone as it has no probability set." ) - current = device.zone["indicies"] - new_zones = current - - while not new_zones[device.zone["index"]] == zone: - tmp = [] - for i in range(1, 10): - tmp.append(new_zones[i]) - tmp.append(new_zones[0]) - new_zones = tmp + current_zones = device.zone["indicies"] + requested_zone_index = current_zones.index(zone) + next_zone_index = device.zone["index"] + + no_indices = len(current_zones) + offset = (requested_zone_index - next_zone_index) % no_indices + new_zones = [] + for i in range(0, no_indices): + new_zones.append(current_zones[(offset + i) % no_indices]) device = DeviceHandler(self._api, mower) self.mqtt.publish(