From f8ba4ded8aab0cb83ecfaa3bde02c419f7eee9ac Mon Sep 17 00:00:00 2001 From: Tom Lawton Date: Wed, 25 Jan 2023 11:24:51 +0000 Subject: [PATCH] #11 Tolerate no `hismap_id`, pick up `map_data` messages if sent --- custom_components/weback_vacuum/VacDevice.py | 6 +++++- custom_components/weback_vacuum/VacMap.py | 5 ++++- custom_components/weback_vacuum/WebackApi.py | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/custom_components/weback_vacuum/VacDevice.py b/custom_components/weback_vacuum/VacDevice.py index 1c4a6f4..a2d4a97 100644 --- a/custom_components/weback_vacuum/VacDevice.py +++ b/custom_components/weback_vacuum/VacDevice.py @@ -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() diff --git a/custom_components/weback_vacuum/VacMap.py b/custom_components/weback_vacuum/VacMap.py index 2c52884..a9cdf52 100644 --- a/custom_components/weback_vacuum/VacMap.py +++ b/custom_components/weback_vacuum/VacMap.py @@ -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): diff --git a/custom_components/weback_vacuum/WebackApi.py b/custom_components/weback_vacuum/WebackApi.py index 56823c2..0e0f5d8 100644 --- a/custom_components/weback_vacuum/WebackApi.py +++ b/custom_components/weback_vacuum/WebackApi.py @@ -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" @@ -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: