Skip to content

Commit

Permalink
Merge pull request #12 from talss89/map-support
Browse files Browse the repository at this point in the history
#11 Tolerate no `hismap_id`, pick up `map_data` messages if sent
  • Loading branch information
Jezza34000 authored Jan 25, 2023
2 parents a01c8fa + 457838e commit dd8210d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion custom_components/weback_vacuum/VacDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ async def watch_state(self):

async def load_maps(self):
"""Load the current reuse map"""
map_data = await self.get_reuse_map_by_id(self.robot_status["hismap_id"], self.sub_type, self.name)

if not self.robot_status[self.ACTIVE_MAP_ID_PROP]:
return False

map_data = await self.get_reuse_map_by_id(self.robot_status[self.ACTIVE_MAP_ID_PROP], self.sub_type, self.name)
if map_data is not []:
self.map = VacMap(map_data)
self.render_map()
Expand Down
5 changes: 4 additions & 1 deletion custom_components/weback_vacuum/VacMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ def wss_update(self, input):

for i, room in enumerate(self.data["room_zone_info"]):
existing_room = next(room for room in existing_room_data if room["room_id"] == self.data["room_zone_info"][i]["room_id"])
self.data["room_zone_info"][i]["room_name"] = existing_room["room_name"]
if "room_name" in existing_room:
self.data["room_zone_info"][i]["room_name"] = existing_room["room_name"]
else:
self.data["room_zone_info"][i]["room_name"] = existing_room["room_id"]


def get_map_bitmap(self):
Expand Down
12 changes: 10 additions & 2 deletions custom_components/weback_vacuum/WebackApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ class WebackWssCtrl(WebackApi):
PLANNING_RECT_POINT_NUM = "planning_rect_point_num"
PLANNING_RECT_X = "planning_rect_x"
PLANNING_RECT_Y = "planning_rect_y"
ACTIVE_MAP_ID_PROP = "hismap_id"

# Payload switches
VOICE_SWITCH = "voice_switch"
Expand Down Expand Up @@ -546,8 +547,15 @@ def on_message(self, ws, message):
_LOGGER.debug('No update from cloud')
elif wss_data["notify_info"] == MAP_DATA:
_LOGGER.debug(f"WebackApi (WSS) Map data received")
self.map.wss_update(wss_data['map_data'])
self.render_map()
try:
if not self.map:
self.map = VacMap(wss_data['map_data'])
else:
self.map.wss_update(wss_data['map_data'])
self.render_map()
except Exception as e:
_LOGGER.error(f"WebackApi (WSS) Error during on_message (map_data) (details={e})")

self.adapt_refresh_time(self.robot_status)
self._call_subscriber()
else:
Expand Down

0 comments on commit dd8210d

Please sign in to comment.