From ca961fc0d47d3994420b616752648ff1ce7081d7 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Sat, 7 May 2022 20:57:28 +0200 Subject: [PATCH] add custom room name (#117) * add custom room name * add tests --- deebot_client/commands/map.py | 8 ++++- deebot_client/events/map.py | 2 +- deebot_client/map.py | 4 +-- deebot_client/models.py | 2 +- tests/commands/test_map.py | 55 +++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 tests/commands/test_map.py diff --git a/deebot_client/commands/map.py b/deebot_client/commands/map.py index 5118e098..69c205ed 100644 --- a/deebot_client/commands/map.py +++ b/deebot_client/commands/map.py @@ -175,6 +175,7 @@ class GetMapSubSet(CommandWithHandling): "12": "Corridor", "13": "Balcony", "14": "Gym", + # 15 custom; get name from name attribute } name = "getMapSubSet" @@ -214,13 +215,18 @@ def _handle_body_data_dict( """ if MapSetType.has_value(data["type"]): subtype = data.get("subtype", data.get("subType", None)) + name = None + if subtype == "15": + name = data.get("name", None) + elif subtype: + name = cls._ROOM_NUM_TO_NAME.get(subtype, None) event_bus.notify( MapSubsetEvent( id=int(data["mssid"]), type=MapSetType(data["type"]), coordinates=data["value"], - subtype=cls._ROOM_NUM_TO_NAME[subtype] if subtype else None, + name=name, ) ) diff --git a/deebot_client/events/map.py b/deebot_client/events/map.py index 9bfe4cf9..3e72321c 100644 --- a/deebot_client/events/map.py +++ b/deebot_client/events/map.py @@ -86,4 +86,4 @@ class MapSubsetEvent(Event): id: int type: MapSetType coordinates: str - subtype: Optional[str] = None + name: Optional[str] = None diff --git a/deebot_client/map.py b/deebot_client/map.py index eef4b8ec..45c17035 100644 --- a/deebot_client/map.py +++ b/deebot_client/map.py @@ -156,8 +156,8 @@ async def on_map_set(event: MapSetEvent) -> None: self._event_bus.subscribe(MapSetEvent, on_map_set) async def on_map_subset(event: MapSubsetEvent) -> None: - if event.type == MapSetType.ROOMS and event.subtype: - room = Room(event.subtype, event.id, event.coordinates) + if event.type == MapSetType.ROOMS and event.name: + room = Room(event.name, event.id, event.coordinates) if self._map_data.rooms.get(event.id, None) != room: self._map_data.rooms[room.id] = room diff --git a/deebot_client/models.py b/deebot_client/models.py index b0f1fe46..94316764 100644 --- a/deebot_client/models.py +++ b/deebot_client/models.py @@ -55,7 +55,7 @@ def get_class(self) -> str: class Room: """Room representation.""" - subtype: str + name: str id: int coordinates: str diff --git a/tests/commands/test_map.py b/tests/commands/test_map.py new file mode 100644 index 00000000..eff8fa1a --- /dev/null +++ b/tests/commands/test_map.py @@ -0,0 +1,55 @@ +from deebot_client.commands import GetMapSubSet +from deebot_client.events import MapSetType, MapSubsetEvent +from tests.commands import assert_command_requested +from tests.helpers import get_request_json + + +def test_getMapSubSet_requested_customName(): + type = MapSetType.ROOMS.value + value = "XQAABAB5AgAAABaOQok5MfkIKbGTBxaUTX13SjXBAI1/Q3A9Kkx2gYZ1QdgwfwOSlU3hbRjNJYgr2Pr3WgFez3Gcoj3R2JmzAuc436F885ZKt5NF2AE1UPAF4qq67tK6TSA64PPfmZQ0lqwInQmqKG5/KO59RyFBbV1NKnDIGNBGVCWpH62WLlMu8N4zotA8dYMQ/UBMwr/gddQO5HU01OQM2YvF" + name = "Levin" + json = get_request_json( + { + "type": type, + "subtype": "15", + "connections": "7,", + "name": name, + "seqIndex": 0, + "seq": 0, + "count": 0, + "totalCount": 50, + "index": 0, + "cleanset": "1,0,2", + "valueSize": 633, + "compress": 1, + "center": "-6775,-9225", + "mssid": "8", + "value": value, + "mid": "98100521", + } + ) + assert_command_requested( + GetMapSubSet(mid="98100521", mssid="8", msid="1"), + json, + MapSubsetEvent(8, type, value, name), + ) + + +def test_getMapSubSet_requested_living_room(): + type = MapSetType.ROOMS.value + 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" + json = get_request_json( + { + "type": type, + "mssid": "7", + "value": value, + "subtype": "1", + "connections": "12", + "mid": "199390082", + } + ) + assert_command_requested( + GetMapSubSet(mid="199390082", mssid="7", msid="1"), + json, + MapSubsetEvent(7, type, value, "Living Room"), + )