-
Notifications
You must be signed in to change notification settings - Fork 94
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
Open
andig
wants to merge
1
commit into
Python-roborock:main
Choose a base branch
from
andig:feat/q7-live-map-push
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,19 +9,22 @@ | |
| """ | ||
|
|
||
| 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.roborock_typing import RoborockB01Q7Methods | ||
|
|
||
| from .map import MapTrait | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| _TRUNCATE_LENGTH = 20 | ||
|
|
||
|
|
||
|
|
@@ -49,7 +52,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 +62,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 +86,23 @@ 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. | ||
| """ | ||
| 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 |
||
| 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: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.