-
Notifications
You must be signed in to change notification settings - Fork 88
chore: add dataclasses for Roborock mower #862
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
+160
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Dataclasses for Roborock mower devices.""" | ||
|
|
||
| from .mower_containers import * |
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,43 @@ | ||
| """Data containers for Roborock mower devices.""" | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from typing import Any | ||
|
|
||
| from roborock.data.containers import RoborockBase | ||
| from roborock.roborock_message import RoborockMowerDataProtocol | ||
|
|
||
|
|
||
| @dataclass | ||
| class MowerStatus(RoborockBase): | ||
| """Core mower status backed by mower DPS updates.""" | ||
|
|
||
| error_code: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.ERROR_CODE}) | ||
| battery: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.BATTERY}) | ||
| mow_type: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_TYPE}) | ||
| mow_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_STATE}) | ||
| mapping_type: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MAPPING_TYPE}) | ||
| mapping_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MAPPING_STATE}) | ||
| ota_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.OTA_STATE}) | ||
| charge_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.CHARGE_STATE}) | ||
| dock_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.DOCK_STATE}) | ||
| charge_type: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.CHARGE_TYPE}) | ||
| pend_type: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.PEND_TYPE}) | ||
| remote_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.REMOTE_STATE}) | ||
| mow_start_type: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_START_TYPE}) | ||
| mow_eff_mode: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_EFF_MODE}) | ||
| mow_height: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_HEIGHT}) | ||
| mow_direction_angle: int | None = field( | ||
| default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_DIRECTION_ANGLE} | ||
| ) | ||
| mow_pattern: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_PATTERN}) | ||
| mow_conf_mode: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_CONF_MODE}) | ||
| offline_status: Any | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.OFFLINE_STATUS}) | ||
| mow_progress: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.MOW_PROGRESS}) | ||
| blade_lifespan: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.BLADE_LIFESPAN}) | ||
| fc_state: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.FC_STATE}) | ||
| gps_coordinate: Any | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.GPS_COORDINATE}) | ||
| off_dock_no_task_status: int | None = field( | ||
| default=None, metadata={"dps": RoborockMowerDataProtocol.OFF_DOCK_NO_TASK_STATUS} | ||
| ) | ||
| afs_status: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.AFS_STATUS}) | ||
| network_channel: int | None = field(default=None, metadata={"dps": RoborockMowerDataProtocol.NETWORK_CHANNEL}) | ||
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,74 @@ | ||
| """Test mower data containers.""" | ||
|
|
||
| import dataclasses | ||
|
|
||
| from roborock.data import MowerStatus | ||
| from roborock.roborock_message import RoborockMowerDataProtocol | ||
|
|
||
|
|
||
| def test_mower_status_from_dict() -> None: | ||
| status = MowerStatus.from_dict( | ||
| { | ||
| "error_code": 0, | ||
| "battery": 82, | ||
| "mow_state": 3, | ||
| "mowHeight": 70, | ||
| "gpsCoordinate": {"latitude": 1, "longitude": 2}, | ||
| "unknown": "ignored", | ||
| } | ||
| ) | ||
|
|
||
| assert status.error_code == 0 | ||
| assert status.battery == 82 | ||
| assert status.mow_state == 3 | ||
| assert status.mow_height == 70 | ||
| assert status.gps_coordinate == {"latitude": 1, "longitude": 2} | ||
|
|
||
|
|
||
| def test_mower_status_dps_metadata() -> None: | ||
| dps_by_field = { | ||
| field.name: field.metadata["dps"] | ||
| for field in dataclasses.fields(MowerStatus) | ||
| if field.metadata and "dps" in field.metadata | ||
| } | ||
|
|
||
| assert dps_by_field == { | ||
| "error_code": RoborockMowerDataProtocol.ERROR_CODE, | ||
| "battery": RoborockMowerDataProtocol.BATTERY, | ||
| "mow_type": RoborockMowerDataProtocol.MOW_TYPE, | ||
| "mow_state": RoborockMowerDataProtocol.MOW_STATE, | ||
| "mapping_type": RoborockMowerDataProtocol.MAPPING_TYPE, | ||
| "mapping_state": RoborockMowerDataProtocol.MAPPING_STATE, | ||
| "ota_state": RoborockMowerDataProtocol.OTA_STATE, | ||
| "charge_state": RoborockMowerDataProtocol.CHARGE_STATE, | ||
| "dock_state": RoborockMowerDataProtocol.DOCK_STATE, | ||
| "charge_type": RoborockMowerDataProtocol.CHARGE_TYPE, | ||
| "pend_type": RoborockMowerDataProtocol.PEND_TYPE, | ||
| "remote_state": RoborockMowerDataProtocol.REMOTE_STATE, | ||
| "mow_start_type": RoborockMowerDataProtocol.MOW_START_TYPE, | ||
| "mow_eff_mode": RoborockMowerDataProtocol.MOW_EFF_MODE, | ||
| "mow_height": RoborockMowerDataProtocol.MOW_HEIGHT, | ||
| "mow_direction_angle": RoborockMowerDataProtocol.MOW_DIRECTION_ANGLE, | ||
| "mow_pattern": RoborockMowerDataProtocol.MOW_PATTERN, | ||
| "mow_conf_mode": RoborockMowerDataProtocol.MOW_CONF_MODE, | ||
| "offline_status": RoborockMowerDataProtocol.OFFLINE_STATUS, | ||
| "mow_progress": RoborockMowerDataProtocol.MOW_PROGRESS, | ||
| "blade_lifespan": RoborockMowerDataProtocol.BLADE_LIFESPAN, | ||
| "fc_state": RoborockMowerDataProtocol.FC_STATE, | ||
| "gps_coordinate": RoborockMowerDataProtocol.GPS_COORDINATE, | ||
| "off_dock_no_task_status": RoborockMowerDataProtocol.OFF_DOCK_NO_TASK_STATUS, | ||
| "afs_status": RoborockMowerDataProtocol.AFS_STATUS, | ||
| "network_channel": RoborockMowerDataProtocol.NETWORK_CHANNEL, | ||
| } | ||
|
|
||
|
|
||
| def test_mower_command_dps_are_not_status_fields() -> None: | ||
| status_dps = { | ||
| field.metadata["dps"] for field in dataclasses.fields(MowerStatus) if field.metadata and "dps" in field.metadata | ||
| } | ||
|
|
||
| assert RoborockMowerDataProtocol.START not in status_dps | ||
| assert RoborockMowerDataProtocol.DOCK not in status_dps | ||
| assert RoborockMowerDataProtocol.PAUSE not in status_dps | ||
| assert RoborockMowerDataProtocol.RESUME not in status_dps | ||
| assert RoborockMowerDataProtocol.STOP not in status_dps |
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.
i assume these will be enums in the future
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.
Yep! Didn't want to get too carried away in the first PR (trying to keep it semi-manageable especially as I am just going off RR_API code). The ones that make sense to be enums will be enums