Skip to content

Commit 7c3461d

Browse files
authored
Add map id to RoomsEvent (#1434)
1 parent fa85dd7 commit 7c3461d

File tree

10 files changed

+38
-19
lines changed

10 files changed

+38
-19
lines changed

deebot_client/commands/json/map/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _handle_subsets(
8484
:return: A message response
8585
"""
8686
subset_ids = [int(subset["mssid"]) for subset in data["subsets"]]
87-
event_bus.notify(MapSetEvent(MapSetType(data["type"]), subset_ids))
87+
event_bus.notify(MapSetEvent(MapSetType(data["type"]), subset_ids, data["mid"]))
8888
return cls._get_handling_success_with_subset_command_args(data, subset_ids)
8989

9090
@classmethod
@@ -236,10 +236,11 @@ def _handle_subsets(
236236
"""
237237
# subset is based64 7z compressed
238238
subsets = orjson.loads(decompress_base64_data(data["subsets"]).decode())
239+
map_id = data["mid"]
239240

240241
match map_type := data["type"]:
241242
case MapSetType.ROOMS:
242-
return cls._handle_rooms_subsets(event_bus, data, subsets)
243+
return cls._handle_rooms_subsets(event_bus, data, subsets, map_id)
243244

244245
case MapSetType.VIRTUAL_WALLS | MapSetType.NO_MOP_ZONES:
245246
subset_ids = []
@@ -258,7 +259,7 @@ def _handle_subsets(
258259
)
259260
subset_ids.append(int(mssid))
260261

261-
event_bus.notify(MapSetEvent(MapSetType(map_type), subset_ids))
262+
event_bus.notify(MapSetEvent(MapSetType(map_type), subset_ids, map_id))
262263
return HandlingResult.success()
263264

264265
return HandlingResult.analyse()
@@ -269,6 +270,7 @@ def _handle_rooms_subsets(
269270
event_bus: EventBus,
270271
data: dict[str, Any],
271272
subsets: list[list[str]],
273+
map_id: str,
272274
) -> HandlingResult:
273275
# there are two versions of this message, depending on the number of values
274276
if subsets and len(subsets[0]) == 10:
@@ -286,7 +288,9 @@ def _handle_rooms_subsets(
286288

287289
# coordinates are sent in the MapInfo_V2 message
288290
event_bus.notify(
289-
RoomsEvent([Room(subset[1], int(subset[0]), "") for subset in subsets])
291+
RoomsEvent(
292+
map_id, [Room(subset[1], int(subset[0]), "") for subset in subsets]
293+
)
290294
)
291295

292296
# GetMapSubSet isn't supported for this robot and not needed
@@ -303,7 +307,7 @@ def _handle_rooms_subsets(
303307
# 8 -> named all as 'settingName1'
304308
# return the subset ids to trigger GetMapSubSet for each one
305309
subset_ids = [int(subset[0]) for subset in subsets]
306-
event_bus.notify(MapSetEvent(MapSetType.ROOMS, subset_ids))
310+
event_bus.notify(MapSetEvent(MapSetType.ROOMS, subset_ids, map_id))
307311
return cls._get_handling_success_with_subset_command_args(data, subset_ids)
308312

309313

deebot_client/commands/xml/map.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
125125

126126
xml_subsets = xml.findall("m")
127127
subsets = cls._find_subsets(xml_subsets)
128-
event_bus.notify(MapSetEvent(MapSetType(area_type), subsets=subsets))
128+
event_bus.notify(
129+
MapSetEvent(MapSetType(area_type), subsets=subsets, map_id=msid)
130+
)
129131
args = {
130132
cls._ARGS_MSID: msid,
131133
cls._ARGS_TYPE: area_type,

deebot_client/events/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class LifeSpanEvent(Event):
170170
class RoomsEvent(Event):
171171
"""Room event representation."""
172172

173+
map_id: str
173174
rooms: list[Room]
174175

175176

deebot_client/events/map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class MapSetEvent(Event):
9393

9494
type: MapSetType
9595
subsets: list[int]
96+
map_id: str
9697

9798

9899
@dataclass(frozen=True)

deebot_client/map.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,13 @@ def __init__(self, event_bus: EventBus, on_change: Callable[[], None]) -> None:
270270
self._amount_rooms: int = 0
271271
self._rooms: OnChangedDict[int, Room] = OnChangedDict(on_change)
272272
self._unsubscribers: list[Callable[[], None]] = []
273+
self._map_id: str = ""
273274

274275
async def on_map_set(event: MapSetEvent) -> None:
275276
if event.type != MapSetType.ROOMS:
276277
return
277278

279+
self._map_id = event.map_id
278280
self._amount_rooms = len(event.subsets)
279281
for room_id in self._rooms.copy():
280282
if room_id not in event.subsets:
@@ -291,7 +293,9 @@ async def on_map_subset(event: MapSubsetEvent) -> None:
291293
self._rooms[room.id] = room
292294

293295
if len(self._rooms) == self._amount_rooms:
294-
event_bus.notify(RoomsEvent(list(self._rooms.values())))
296+
event_bus.notify(
297+
RoomsEvent(self._map_id, list(self._rooms.values()))
298+
)
295299

296300
self._unsubscribers.append(event_bus.subscribe(MapSubsetEvent, on_map_subset))
297301

tests/commands/json/map/test_init.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async def test_getMapSet() -> None:
206206
for subset in subsets
207207
),
208208
)
209-
events = [firmware_event, MapSetEvent(MapSetType.ROOMS, subsets)]
209+
events = [firmware_event, MapSetEvent(MapSetType.ROOMS, subsets, mid)]
210210
for subset in subsets:
211211
events.extend(
212212
[
@@ -255,7 +255,7 @@ async def test_getMapSet() -> None:
255255
MapSetType.VIRTUAL_WALLS,
256256
"['2120', '-4581', '2106', '-6271']",
257257
),
258-
MapSetEvent(MapSetType.VIRTUAL_WALLS, [0, 1]),
258+
MapSetEvent(MapSetType.VIRTUAL_WALLS, [0, 1], "1132127808"),
259259
],
260260
),
261261
(
@@ -276,7 +276,7 @@ async def test_getMapSet() -> None:
276276
MapSetType.NO_MOP_ZONES,
277277
"['-6217', '3919', '-6217', '231', '-2642', '231', '-2642', '3919']",
278278
),
279-
MapSetEvent(MapSetType.NO_MOP_ZONES, [4]),
279+
MapSetEvent(MapSetType.NO_MOP_ZONES, [4], "199390082"),
280280
],
281281
),
282282
(
@@ -312,7 +312,7 @@ async def test_getMapSet() -> None:
312312
MapSetType.VIRTUAL_WALLS,
313313
"['-5667', '317', '-4888', '-56']",
314314
),
315-
MapSetEvent(MapSetType.VIRTUAL_WALLS, [0, 1, 2, 3]),
315+
MapSetEvent(MapSetType.VIRTUAL_WALLS, [0, 1, 2, 3], "199390082"),
316316
],
317317
),
318318
(
@@ -338,7 +338,7 @@ async def test_getMapSet() -> None:
338338
MapSetType.VIRTUAL_WALLS,
339339
"['3315', '3754', '3353', '-655']",
340340
),
341-
MapSetEvent(MapSetType.VIRTUAL_WALLS, [0, 1]),
341+
MapSetEvent(MapSetType.VIRTUAL_WALLS, [0, 1], "199390082"),
342342
],
343343
),
344344
],
@@ -390,7 +390,7 @@ async def test_getMapSetV2_rooms() -> None:
390390
for subset in subsets
391391
),
392392
)
393-
events = [firmware_event, MapSetEvent(MapSetType(set_type), subsets)]
393+
events = [firmware_event, MapSetEvent(MapSetType(set_type), subsets, mid)]
394394
for subset in subsets:
395395
events.extend(
396396
[
@@ -454,7 +454,7 @@ async def test_getMapSetV2_rooms_v2() -> None:
454454
Room(room_name, subset, "")
455455
for subset, room_name in zip(subsets, rooms_names, strict=False)
456456
]
457-
events = [firmware_event, RoomsEvent(rooms)]
457+
events = [firmware_event, RoomsEvent(mid, rooms)]
458458

459459
await assert_command(
460460
GetMapSetV2(mid, set_type),

tests/commands/xml/test_map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ async def test_GetMapSet(
107107
MapSetEvent(
108108
map_type if isinstance(map_type, MapSetType) else MapSetType(map_type),
109109
subsets=subsets,
110+
map_id="1",
110111
),
111112
handling_result=HandlingResult(
112113
HandlingState.SUCCESS,

tests/data/map/test_1.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@
120120
index=26,
121121
value="XQAABAAQJwAAAABv/f//o7f/Rz5IFXI5YVG4kijmo4YH+e7kHoLTL8U6OwczrMl+5Cn+j6EvprKUdquBVZgFpQToAHLTz2AlAA==",
122122
),
123-
MapSetEvent(type=MapSetType.ROOMS, subsets=[5, 8, 10, 3, 4, 7, 9]),
123+
MapSetEvent(
124+
type=MapSetType.ROOMS, subsets=[5, 8, 10, 3, 4, 7, 9], map_id="1132127808"
125+
),
124126
MapSubsetEvent(
125127
id=0,
126128
type=MapSetType.VIRTUAL_WALLS,

tests/data/map/test_2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
Position(type=PositionType.CHARGER, x=-384, y=-360, a=43),
2222
]
2323
),
24-
MapSetEvent(type=MapSetType.ROOMS, subsets=[5, 8, 10, 3, 4, 7, 9]),
24+
MapSetEvent(
25+
type=MapSetType.ROOMS, subsets=[5, 8, 10, 3, 4, 7, 9], map_id="1132127808"
26+
),
2527
MapSubsetEvent(
2628
id=0,
2729
type=MapSetType.VIRTUAL_WALLS,
@@ -34,7 +36,7 @@
3436
coordinates="['2120', '-4581', '2106', '-6271']",
3537
name=None,
3638
),
37-
MapSetEvent(type=MapSetType.VIRTUAL_WALLS, subsets=[0, 1]),
39+
MapSetEvent(type=MapSetType.VIRTUAL_WALLS, subsets=[0, 1], map_id="1132127808"),
3840
MapSubsetEvent(
3941
id=2,
4042
type=MapSetType.NO_MOP_ZONES,

tests/data/map/test_4.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
Position(type=PositionType.CHARGER, x=-384, y=-360, a=43),
2121
]
2222
),
23-
MapSetEvent(type=MapSetType.ROOMS, subsets=[5, 8, 10, 3, 4, 7, 9]),
23+
MapSetEvent(
24+
type=MapSetType.ROOMS, subsets=[5, 8, 10, 3, 4, 7, 9], map_id="1132127808"
25+
),
2426
MapSubsetEvent(
2527
id=0,
2628
type=MapSetType.VIRTUAL_WALLS,
@@ -33,7 +35,7 @@
3335
coordinates="['2120', '-4581', '2106', '-6271']",
3436
name=None,
3537
),
36-
MapSetEvent(type=MapSetType.VIRTUAL_WALLS, subsets=[0, 1]),
38+
MapSetEvent(type=MapSetType.VIRTUAL_WALLS, subsets=[0, 1], map_id="1132127808"),
3739
MapSubsetEvent(
3840
id=2,
3941
type=MapSetType.NO_MOP_ZONES,

0 commit comments

Comments
 (0)