-
-
Notifications
You must be signed in to change notification settings - Fork 197
Implement XML Position messages #916
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
Merged
edenhaus
merged 6 commits into
DeebotUniverse:dev
from
nanomad:feature/xml-messages-pos
Apr 25, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4262a01
Add XML Position messages
nanomad 073edee
Introduce GetChargerPos command and Pos parser class
nanomad e21500e
Add more tests
nanomad e363ad0
Add more checks to Pos message parsing
nanomad 20b064d
Fix tests
nanomad a8efe15
Integrate PR feedback
nanomad 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
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Pos messages.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from deebot_client.events import Position, PositionsEvent | ||
| from deebot_client.message import HandlingResult | ||
| from deebot_client.messages.xml.common import XmlMessage | ||
| from deebot_client.rs.map import PositionType | ||
|
|
||
| if TYPE_CHECKING: | ||
| from xml.etree.ElementTree import Element | ||
|
|
||
| from deebot_client.event_bus import EventBus | ||
|
|
||
|
|
||
| class Pos(XmlMessage): | ||
| """Pos message.""" | ||
|
|
||
| NAME = "Pos" | ||
|
|
||
| @classmethod | ||
| def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult: | ||
| if xml.attrib.get("t") != "p": | ||
| return HandlingResult.analyse() | ||
|
|
||
| return cls._parse_xml(PositionType.DEEBOT, event_bus, xml) | ||
|
|
||
| @classmethod | ||
| def _parse_xml( | ||
| cls, position_type: PositionType, event_bus: EventBus, xml: Element | ||
| ) -> HandlingResult: | ||
| """Handle xml message and notify the correct event subscribers.""" | ||
| if (p := xml.attrib.get("p")) and (xml.attrib.get("valid", "1")) == "1": | ||
| p_x, p_y = p.split(",", 2) | ||
| p_a = xml.attrib.get("a", 0) | ||
| position = Position(type=position_type, x=int(p_x), y=int(p_y), a=int(p_a)) | ||
| event_bus.notify(PositionsEvent(positions=[position])) | ||
| return HandlingResult.success() | ||
|
|
||
| return HandlingResult.analyse() |
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from deebot_client.events import Position, PositionsEvent | ||
| from deebot_client.message import HandlingState | ||
| from deebot_client.messages.xml import Pos | ||
| from deebot_client.rs.map import PositionType | ||
| from tests.messages import assert_message, assert_message_failure | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("position", [(-9, 15, 89)]) | ||
| def test_Pos(position: tuple[int, int, int]) -> None: | ||
| x, y, a = position | ||
| xml_message = f'<ctl td="Pos" t="p" p="{x},{y}" a="{a}" valid="1" />' | ||
| assert_message( | ||
| Pos, | ||
| xml_message, | ||
| PositionsEvent([Position(type=PositionType.DEEBOT, x=x, y=y, a=a)]), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "xml_message", | ||
| { | ||
| '<ctl td="Pos" t="p" a="89" valid="1" />', | ||
| '<ctl td="Pos" t="??" p="0,0" a="89" valid="1" />', | ||
| '<ctl td="Pos" t="p" p="0,0" a="89" valid="0" />', | ||
| }, | ||
| ) | ||
| def test_Pos_error(xml_message: str) -> None: | ||
| assert_message_failure(Pos, xml_message, HandlingState.ANALYSE_LOGGED) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions about the message:
tthe type and will it be different for the charger position?validattribute... I would assume that the position is only valid if it is equal to 1. Can you please verify itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a GetChargerPos command, but I didn't find any "Pos" events for it.
Suggestion: