Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 96
feat: live Q7 (B01) map updates from unsolicited map pushes#912
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,20 +9,24 @@ | ||
| """ | ||
| import asyncio | ||
| import logging | ||
| 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 Q7MapRpcChannel | ||
| from roborock.devices.traits import Trait | ||
| from roborock.devices.traits.common import TraitUpdateListener | ||
| from roborock.exceptions import RoborockException | ||
| from roborock.map.b01_map_parser import B01MapParser, B01MapParserConfig | ||
| from roborock.map.b01_map_parser import B01MapParser, B01MapParserConfig, parse_map_type | ||
| from roborock.roborock_typing import RoborockB01Q7Methods | ||
| from .map import MapTrait | ||
| _LOGGER = logging.getLogger(__name__) | ||
| _TRUNCATE_LENGTH = 20 | ||
| _LIVE_MAP_TYPE = 0 | ||
| @dataclass | ||
| @@ -49,7 +53,7 @@ def __repr__(self) -> str: | ||
| return f"MapContent(image_content={img!r}, map_data={self.map_data!r})" | ||
| class MapContentTrait(MapContent, Trait): | ||
| class MapContentTrait(MapContent, Trait, TraitUpdateListener): | ||
| """Trait for fetching parsed map content for Q7 devices.""" | ||
| def __init__( | ||
| @@ -59,7 +63,8 @@ def __init__( | ||
| *, | ||
| map_parser_config: B01MapParserConfig | None = None, | ||
| ) -> None: | ||
| super().__init__() | ||
| MapContent.__init__(self) | ||
| TraitUpdateListener.__init__(self, logger=_LOGGER) | ||
| self._map_rpc_channel = map_rpc_channel | ||
| self._map_trait = map_trait | ||
| self._map_parser = B01MapParser(map_parser_config) | ||
| @@ -82,6 +87,34 @@ async def refresh(self) -> None: | ||
| {"map_id": map_id}, | ||
| ) | ||
| self._parse_and_store(raw_payload) | ||
| def update_from_push(self, raw_payload: bytes) -> None: | ||
| """Store an unsolicited SCMap frame pushed by the device during cleaning. | ||
| Pushed frames carry the live robot pose and cleaning path, so the | ||
| rendered image stays current without polling. Frames for other maps | ||
| than the live one are ignored to not overwrite the current map. | ||
| """ | ||
| try: | ||
| map_type = parse_map_type(raw_payload) | ||
| except RoborockException as ex: | ||
| _LOGGER.debug("Failed to parse pushed B01 map frame: %s", ex) | ||
| return | ||
| if map_type != _LIVE_MAP_TYPE: | ||
| _LOGGER.debug("Ignoring pushed B01 map frame of type %s", map_type) | ||
| return | ||
| try: | ||
| self._parse_and_store(raw_payload) | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may need to check:
I think there's a chance this could update us for a non-live map and cause confusion and bad updates Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch — fixed in 60aeaae.
Added 🤖 Generated with Claude Code | ||
| except RoborockException as ex: | ||
| _LOGGER.debug("Failed to parse pushed B01 map frame: %s", ex) | ||
| return | ||
| self._notify_update() | ||
| def _parse_and_store(self, raw_payload: bytes) -> None: | ||
| """Parse decoded SCMap bytes and update the cached fields.""" | ||
| try: | ||
| parsed_data = self._map_parser.parse(raw_payload) | ||
| except RoborockException: | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.