Skip to content

Commit ca961fc

Browse files
authored
add custom room name (#117)
* add custom room name * add tests
1 parent c3f7668 commit ca961fc

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

deebot_client/commands/map.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class GetMapSubSet(CommandWithHandling):
175175
"12": "Corridor",
176176
"13": "Balcony",
177177
"14": "Gym",
178+
# 15 custom; get name from name attribute
178179
}
179180

180181
name = "getMapSubSet"
@@ -214,13 +215,18 @@ def _handle_body_data_dict(
214215
"""
215216
if MapSetType.has_value(data["type"]):
216217
subtype = data.get("subtype", data.get("subType", None))
218+
name = None
219+
if subtype == "15":
220+
name = data.get("name", None)
221+
elif subtype:
222+
name = cls._ROOM_NUM_TO_NAME.get(subtype, None)
217223

218224
event_bus.notify(
219225
MapSubsetEvent(
220226
id=int(data["mssid"]),
221227
type=MapSetType(data["type"]),
222228
coordinates=data["value"],
223-
subtype=cls._ROOM_NUM_TO_NAME[subtype] if subtype else None,
229+
name=name,
224230
)
225231
)
226232

deebot_client/events/map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ class MapSubsetEvent(Event):
8686
id: int
8787
type: MapSetType
8888
coordinates: str
89-
subtype: Optional[str] = None
89+
name: Optional[str] = None

deebot_client/map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ async def on_map_set(event: MapSetEvent) -> None:
156156
self._event_bus.subscribe(MapSetEvent, on_map_set)
157157

158158
async def on_map_subset(event: MapSubsetEvent) -> None:
159-
if event.type == MapSetType.ROOMS and event.subtype:
160-
room = Room(event.subtype, event.id, event.coordinates)
159+
if event.type == MapSetType.ROOMS and event.name:
160+
room = Room(event.name, event.id, event.coordinates)
161161
if self._map_data.rooms.get(event.id, None) != room:
162162
self._map_data.rooms[room.id] = room
163163

deebot_client/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_class(self) -> str:
5555
class Room:
5656
"""Room representation."""
5757

58-
subtype: str
58+
name: str
5959
id: int
6060
coordinates: str
6161

tests/commands/test_map.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from deebot_client.commands import GetMapSubSet
2+
from deebot_client.events import MapSetType, MapSubsetEvent
3+
from tests.commands import assert_command_requested
4+
from tests.helpers import get_request_json
5+
6+
7+
def test_getMapSubSet_requested_customName():
8+
type = MapSetType.ROOMS.value
9+
value = "XQAABAB5AgAAABaOQok5MfkIKbGTBxaUTX13SjXBAI1/Q3A9Kkx2gYZ1QdgwfwOSlU3hbRjNJYgr2Pr3WgFez3Gcoj3R2JmzAuc436F885ZKt5NF2AE1UPAF4qq67tK6TSA64PPfmZQ0lqwInQmqKG5/KO59RyFBbV1NKnDIGNBGVCWpH62WLlMu8N4zotA8dYMQ/UBMwr/gddQO5HU01OQM2YvF"
10+
name = "Levin"
11+
json = get_request_json(
12+
{
13+
"type": type,
14+
"subtype": "15",
15+
"connections": "7,",
16+
"name": name,
17+
"seqIndex": 0,
18+
"seq": 0,
19+
"count": 0,
20+
"totalCount": 50,
21+
"index": 0,
22+
"cleanset": "1,0,2",
23+
"valueSize": 633,
24+
"compress": 1,
25+
"center": "-6775,-9225",
26+
"mssid": "8",
27+
"value": value,
28+
"mid": "98100521",
29+
}
30+
)
31+
assert_command_requested(
32+
GetMapSubSet(mid="98100521", mssid="8", msid="1"),
33+
json,
34+
MapSubsetEvent(8, type, value, name),
35+
)
36+
37+
38+
def test_getMapSubSet_requested_living_room():
39+
type = MapSetType.ROOMS.value
40+
value = "-1400,-1600;-1400,-1350;-950,-1100;-900,-150;-550,100;200,950;500,950;650,800;800,950;1850,950;1950,800;1950,-200;2050,-300;2300,-300;2550,-650;2700,-650;2700,-1600;2400,-1750;2700,-1900;2700,-2950;2450,-2950;2300,-3100;2400,-3200;2650,-3200;2700,-3500;2300,-3500;2200,-3250;2050,-3550;1200,-3550;1200,-3300;1050,-3200;950,-3300;950,-3550;600,-3550;550,-2850;850,-2800;950,-2700;850,-2600;950,-2400;900,-2350;800,-2300;550,-2500;550,-2350;400,-2250;200,-2650;-800,-2650;-950,-2550;-950,-2150;-650,-2000;-450,-2000;-400,-1950;-450,-1850;-750,-1800;-950,-1900;-1350,-1900;-1400,-1600"
41+
json = get_request_json(
42+
{
43+
"type": type,
44+
"mssid": "7",
45+
"value": value,
46+
"subtype": "1",
47+
"connections": "12",
48+
"mid": "199390082",
49+
}
50+
)
51+
assert_command_requested(
52+
GetMapSubSet(mid="199390082", mssid="7", msid="1"),
53+
json,
54+
MapSubsetEvent(7, type, value, "Living Room"),
55+
)

0 commit comments

Comments
 (0)