Skip to content

Commit

Permalink
Merge pull request #197 from sithmein/issue-196
Browse files Browse the repository at this point in the history
Update internal mower state upon update message
  • Loading branch information
MTrab committed Mar 27, 2024
2 parents 9cb7a91 + d789a11 commit 7d50430
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pyworxcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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"]:
Expand Down Expand Up @@ -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("/")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -905,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
current_zones = device.zone["indicies"]
requested_zone_index = current_zones.index(zone)
next_zone_index = device.zone["index"]

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
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(
Expand Down

0 comments on commit 7d50430

Please sign in to comment.