-
Notifications
You must be signed in to change notification settings - Fork 87
Initial room configuration support for Q10 devices #837
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
lboue
wants to merge
1
commit into
Python-roborock:main
Choose a base branch
from
lboue:q10_rooms
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.
+607
−0
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Rooms trait for Q10 B01 devices.""" | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP | ||
| from roborock.data.b01_q10.b01_q10_containers import ( | ||
| Q10RoomConfig, | ||
| Q10RoomsConfig, | ||
| parse_customer_clean_payload, | ||
| ) | ||
| from roborock.devices.traits.common import TraitUpdateListener | ||
|
|
||
| from .command import CommandTrait | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class RoomsTrait(Q10RoomsConfig, TraitUpdateListener): | ||
| """Trait for managing Q10 room configuration.""" | ||
|
|
||
| def __init__(self, command: CommandTrait) -> None: | ||
| super().__init__() | ||
| TraitUpdateListener.__init__(self, logger=_LOGGER) | ||
| self._command = command | ||
|
|
||
| async def refresh(self) -> None: | ||
| """Request the current room configuration from the device.""" | ||
| await self._command.send(B01_Q10_DP.COMMON, params={B01_Q10_DP.CUSTOMER_CLEAN_REQUEST.code: 0}) | ||
|
|
||
| @property | ||
| def room_map(self) -> dict[int, Q10RoomConfig]: | ||
| """Return the current room configurations keyed by room id.""" | ||
| return {room.room_id: room for room in self.rooms} | ||
|
|
||
| @property | ||
| def room_names(self) -> dict[int, str]: | ||
| """Return the current room names keyed by room id.""" | ||
| return {room.room_id: room.room_name for room in self.rooms} | ||
|
|
||
| def get_room(self, room_id: int) -> Q10RoomConfig | None: | ||
| """Return a room configuration by room id, if known.""" | ||
| return self.room_map.get(int(room_id)) | ||
|
|
||
| def get_room_name(self, room_id: int, default: str | None = None) -> str | None: | ||
| """Return a room name by room id, optionally with a default.""" | ||
| room = self.get_room(room_id) | ||
| if room is None: | ||
| return default | ||
| return room.room_name | ||
|
|
||
| def update_from_dps(self, decoded_dps: dict[B01_Q10_DP, Any]) -> None: | ||
| """Update the trait from raw DPS data.""" | ||
| payload = decoded_dps.get(B01_Q10_DP.CUSTOMER_CLEAN) | ||
| if not isinstance(payload, str): | ||
| return | ||
|
|
||
| try: | ||
| parsed = parse_customer_clean_payload(payload) | ||
| except Exception: | ||
| _LOGGER.debug("Failed to parse CUSTOMER_CLEAN payload", exc_info=True) | ||
| return | ||
|
|
||
| changed = ( | ||
| self.raw_length != parsed.raw_length | ||
| or self.declared_count != parsed.declared_count | ||
| or self.rooms != parsed.rooms | ||
| ) | ||
| self.raw_length = parsed.raw_length | ||
| self.declared_count = parsed.declared_count | ||
| self.rooms = parsed.rooms | ||
| if changed: | ||
| self._notify_update() |
Oops, something went wrong.
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.