-
Notifications
You must be signed in to change notification settings - Fork 77
chore: update map-related commands and payload decoding for B01/Q7 devices #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d9211b2
ea5d444
6ac8462
4bd97fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,14 +8,18 @@ | |||||||||||||||||||||||||||||||||||||||||||
| For B01/Q7 devices, the underlying raw map payload is retrieved via `MapTrait`. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import asyncio | ||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from vacuum_map_parser_base.map_data import MapData | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from roborock.data import RoborockBase | ||||||||||||||||||||||||||||||||||||||||||||
| from roborock.devices.rpc.b01_q7_channel import MapRpcChannel | ||||||||||||||||||||||||||||||||||||||||||||
| from roborock.devices.traits import Trait | ||||||||||||||||||||||||||||||||||||||||||||
| from roborock.exceptions import RoborockException | ||||||||||||||||||||||||||||||||||||||||||||
| from roborock.map.b01_map_parser import B01MapParser, B01MapParserConfig | ||||||||||||||||||||||||||||||||||||||||||||
| from roborock.protocols.b01_q7_protocol import B01_Q7_DPS, Q7RequestMessage | ||||||||||||||||||||||||||||||||||||||||||||
| from roborock.roborock_typing import RoborockB01Q7Methods | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from .map import MapTrait | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -51,48 +55,46 @@ class MapContentTrait(MapContent, Trait): | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def __init__( | ||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||
| map_rpc_channel: MapRpcChannel, | ||||||||||||||||||||||||||||||||||||||||||||
| map_trait: MapTrait, | ||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||
| serial: str, | ||||||||||||||||||||||||||||||||||||||||||||
| model: str, | ||||||||||||||||||||||||||||||||||||||||||||
| map_parser_config: B01MapParserConfig | None = None, | ||||||||||||||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||||||||||||||
| super().__init__() | ||||||||||||||||||||||||||||||||||||||||||||
| self._map_rpc_channel = map_rpc_channel | ||||||||||||||||||||||||||||||||||||||||||||
| self._map_trait = map_trait | ||||||||||||||||||||||||||||||||||||||||||||
| self._serial = serial | ||||||||||||||||||||||||||||||||||||||||||||
| self._model = model | ||||||||||||||||||||||||||||||||||||||||||||
| self._map_parser = B01MapParser(map_parser_config) | ||||||||||||||||||||||||||||||||||||||||||||
| # Map uploads are serialized per-device to avoid response cross-wiring. | ||||||||||||||||||||||||||||||||||||||||||||
| self._map_command_lock = asyncio.Lock() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| async def refresh(self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||
| """Fetch, decode, and parse the current map payload.""" | ||||||||||||||||||||||||||||||||||||||||||||
| raw_payload = await self._map_trait.get_current_map_payload() | ||||||||||||||||||||||||||||||||||||||||||||
| parsed = self.parse_map_content(raw_payload) | ||||||||||||||||||||||||||||||||||||||||||||
| self.image_content = parsed.image_content | ||||||||||||||||||||||||||||||||||||||||||||
| self.map_data = parsed.map_data | ||||||||||||||||||||||||||||||||||||||||||||
| self.raw_api_response = parsed.raw_api_response | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def parse_map_content(self, response: bytes) -> MapContent: | ||||||||||||||||||||||||||||||||||||||||||||
| """Parse map content from raw bytes. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| This mirrors the v1 trait behavior so cached map payload bytes can be | ||||||||||||||||||||||||||||||||||||||||||||
| reparsed without going back to the device. | ||||||||||||||||||||||||||||||||||||||||||||
| """Fetch, decode, and parse the current map payload. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| This relies on the Map Trait already having fetched the map list metadata | ||||||||||||||||||||||||||||||||||||||||||||
| so it can determine the current map_id. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| # Users must call first | ||||||||||||||||||||||||||||||||||||||||||||
| if (map_id := self._map_trait.current_map_id) is None: | ||||||||||||||||||||||||||||||||||||||||||||
| raise RoborockException("Unable to determine current map ID") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+79
|
||||||||||||||||||||||||||||||||||||||||||||
| This relies on the Map Trait already having fetched the map list metadata | |
| so it can determine the current map_id. | |
| """ | |
| # Users must call first | |
| if (map_id := self._map_trait.current_map_id) is None: | |
| raise RoborockException("Unable to determine current map ID") | |
| This primarily relies on the Map Trait having fetched the map list | |
| metadata so it can determine the current map_id, but will fall back to | |
| auto-refreshing the map list if needed. | |
| """ | |
| map_id = self._map_trait.current_map_id | |
| if map_id is None: | |
| # Attempt to auto-refresh map metadata so we can determine map_id. | |
| await self._map_trait.refresh() | |
| map_id = self._map_trait.current_map_id | |
| if map_id is None: | |
| raise RoborockException( | |
| "Unable to determine current map ID even after refreshing map " | |
| "metadata; ensure at least one map exists on the device." | |
| ) |
Uh oh!
There was an error while loading. Please reload this page.