@@ -36,10 +36,22 @@ def __init__(self, channel: MqttChannel) -> None:
3636 self ._channel = channel
3737 # Map uploads are serialized per-device to avoid response cross-wiring.
3838 self ._map_command_lock = asyncio .Lock ()
39- self ._map_list_cache : Q7MapList | None = None
39+ self ._map_list : Q7MapList | None = None
4040
41- async def refresh_map_list (self ) -> Q7MapList :
42- """Fetch and cache map list metadata from the robot."""
41+ @property
42+ def map_list (self ) -> Q7MapList | None :
43+ """Latest cached map list metadata, populated by ``refresh()``."""
44+ return self ._map_list
45+
46+ @property
47+ def current_map_id (self ) -> int | None :
48+ """Current map id derived from cached map list metadata."""
49+ if self ._map_list is None :
50+ return None
51+ return self ._extract_current_map_id (self ._map_list )
52+
53+ async def refresh (self ) -> None :
54+ """Refresh cached map list metadata from the device."""
4355 response = await send_decoded_command (
4456 self ._channel ,
4557 Q7RequestMessage (dps = _Q7_DPS , command = RoborockB01Q7Methods .GET_MAP_LIST , params = {}),
@@ -51,24 +63,9 @@ async def refresh_map_list(self) -> Q7MapList:
5163 if parsed is None :
5264 raise TypeError (f"Failed to decode map list response: { response !r} " )
5365
54- self ._map_list_cache = parsed
55- return parsed
56-
57- async def get_map_list (self , * , refresh : bool = False ) -> Q7MapList :
58- """Return cached map list metadata, refreshing when requested or absent."""
59- if refresh or self ._map_list_cache is None :
60- return await self .refresh_map_list ()
61- return self ._map_list_cache
66+ self ._map_list = parsed
6267
63- async def get_current_map_id (self , * , refresh : bool = False ) -> int :
64- """Resolve and return the currently active map id from map list metadata."""
65- map_list = await self .get_map_list (refresh = refresh )
66- map_id = self ._extract_current_map_id (map_list )
67- if map_id is None :
68- raise RoborockException (f"Unable to determine map_id from map list response: { map_list !r} " )
69- return map_id
70-
71- async def get_map_payload (self , * , map_id : int ) -> bytes :
68+ async def _get_map_payload (self , * , map_id : int ) -> bytes :
7269 """Fetch raw map payload bytes for the given map id."""
7370 request = Q7RequestMessage (
7471 dps = _Q7_DPS ,
@@ -78,10 +75,15 @@ async def get_map_payload(self, *, map_id: int) -> bytes:
7875 async with self ._map_command_lock :
7976 return await send_map_command (self ._channel , request )
8077
81- async def get_current_map_payload (self , * , refresh_map_list : bool = False ) -> bytes :
78+ async def get_current_map_payload (self ) -> bytes :
8279 """Fetch raw map payload bytes for the currently selected map."""
83- map_id = await self .get_current_map_id (refresh = refresh_map_list )
84- return await self .get_map_payload (map_id = map_id )
80+ if self ._map_list is None :
81+ await self .refresh ()
82+
83+ map_id = self .current_map_id
84+ if map_id is None :
85+ raise RoborockException (f"Unable to determine map_id from map list response: { self ._map_list !r} " )
86+ return await self ._get_map_payload (map_id = map_id )
8587
8688 @staticmethod
8789 def _extract_current_map_id (map_list_response : Q7MapList ) -> int | None :
0 commit comments