Skip to content

Commit

Permalink
Fixing missing zone mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
MTrab committed May 16, 2023
1 parent fedbde5 commit e290a63
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pyworxcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _decode_data(self, device: DeviceHandler) -> None:
data = device.json_data
elif device.raw_data:
logger.debug("Found raw data: %s", device.raw_data)
data = json.loads(device.raw_data)
data = device.raw_data
else:
device.is_decoded = True
logger.debug("No valid data was found, skipping update for %s", device.name)
Expand Down Expand Up @@ -505,6 +505,7 @@ def _fetch(self) -> None:
_LOGGER.debug("Mower '%s' data: %s", mower["name"], mower)
self.devices.update({mower["name"]: device})

device.raw_data = mower["last_status"]["payload"]
self._decode_data(device)

def get_mower(self, serial_number: str) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion pyworxcloud/utils/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __mapinfo(self, api: Any, data: Any) -> None:
self.capabilities = Capability(data)
self.rainsensor = Rainsensor()
self.status = States()
self.zone = Zone()
self.zone = Zone(data)
self.warranty = Warranty(data)
self.firmware = Firmware(data)
self.schedules = Schedule(data)
Expand Down
10 changes: 9 additions & 1 deletion pyworxcloud/utils/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Zone(LDict):
"""Class for handling zone data."""

def __init__(self) -> dict:
def __init__(self, data) -> dict:
"""Initialize zone object."""
super().__init__()

Expand All @@ -16,6 +16,14 @@ def __init__(self) -> dict:
self["indicies"] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
self["starting_point"] = [0, 0, 0, 0]

if not "last_status" in data:
return

self["index"] = data["last_status"]["payload"]["dat"]["lz"]
self["indicies"] = data["last_status"]["payload"]["cfg"]["mzv"]
self["starting_point"] = data["last_status"]["payload"]["cfg"]["mz"]
self["current"] = self["indicies"][self["index"]]

@property
def current(self) -> int:
"""Get current zone."""
Expand Down
4 changes: 3 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
cloud.authenticate()
cloud.connect()

print(vars(cloud))
cloud.setzone("20213028401100013915", 2)

# print(vars(cloud))

cloud.disconnect()

0 comments on commit e290a63

Please sign in to comment.