-
Notifications
You must be signed in to change notification settings - Fork 75
feat: Improve room naming and data integration #781
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
Changes from 1 commit
bbb6cda
dcf4df9
238f897
562b8d3
924f106
532f108
27221b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,8 @@ | |
| import logging | ||
| from typing import Self | ||
|
|
||
| from roborock.data import CombinedMapInfo, NamedRoomMapping, RoborockBase | ||
| from roborock.data import CombinedMapInfo, MultiMapsListMapInfo, RoborockBase | ||
| from roborock.data.containers import NamedRoomMapping | ||
|
allenporter marked this conversation as resolved.
Outdated
|
||
| from roborock.data.v1.v1_code_mappings import RoborockStateCode | ||
| from roborock.devices.cache import DeviceCache | ||
| from roborock.devices.traits.v1 import common | ||
|
|
@@ -114,35 +115,29 @@ async def discover_home(self) -> None: | |
| self._discovery_completed = True | ||
| await self._update_home_cache(home_map_info, home_map_content) | ||
|
|
||
| async def _refresh_map_info(self, map_info) -> CombinedMapInfo: | ||
| async def _refresh_map_info(self, map_info: MultiMapsListMapInfo) -> CombinedMapInfo: | ||
| """Collect room data for a specific map and return CombinedMapInfo.""" | ||
| await self._rooms_trait.refresh() | ||
|
|
||
| rooms: dict[int, NamedRoomMapping] = {} | ||
| if map_info.rooms: | ||
| # Not all vacuums respond with rooms inside map_info. | ||
| # If we can determine if all vacuums will return everything with get_rooms, we could remove this step. | ||
| for room in map_info.rooms: | ||
| if room.id is not None and room.iot_name_id is not None: | ||
| rooms[room.id] = NamedRoomMapping( | ||
| segment_id=room.id, | ||
| iot_id=room.iot_name_id, | ||
| name=room.iot_name or f"Room {room.id}", | ||
| ) | ||
|
|
||
| # Add rooms from rooms_trait. | ||
| # Keep existing names from map_info unless they are fallback names. | ||
| if self._rooms_trait.rooms: | ||
| for room in self._rooms_trait.rooms: | ||
| if room.segment_id is not None and room.name: | ||
| existing_room = rooms.get(room.segment_id) | ||
| if existing_room is None or existing_room.name == f"Room {room.segment_id}": | ||
| rooms[room.segment_id] = room | ||
|
|
||
| # We have room names from two sources. The map_info.rooms which we just | ||
| # received from the MultiMapsList or the self._rooms_trait.rooms which | ||
| # comes from the GET_ROOM_MAPPING command. We merge them, giving priority | ||
|
allenporter marked this conversation as resolved.
Outdated
|
||
| # to map_info rooms, and excluding unset rooms from the trait. | ||
| rooms: list[NamedRoomMapping] = list( | ||
|
allenporter marked this conversation as resolved.
Outdated
|
||
| { | ||
| **map_info.rooms_map, | ||
| **{ | ||
| room.segment_id: room | ||
| for room in self._rooms_trait.rooms or () | ||
|
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. Could it be worthwhile to set .rooms to a property? I'm figuring we do this other places as well, may be easier to just know we can always assume it is a list. Not needed for this PR though, just a thought
Contributor
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. Would it be current_rooms?
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 that makes sense!
Contributor
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. This depends on one of the map infos returned from an RPC before it is saved so I don't think this works. I still added the attribute, but it won't make this code simpler. |
||
| if (existing := map_info.rooms_map.get(room.segment_id)) is None | ||
| or (room.raw_name and existing.raw_name is None) | ||
|
allenporter marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }.values() | ||
| ) | ||
| return CombinedMapInfo( | ||
| map_flag=map_info.map_flag, | ||
| name=map_info.name, | ||
| rooms=list(rooms.values()), | ||
| rooms=rooms, | ||
| ) | ||
|
|
||
| async def _refresh_map_content(self) -> MapContent: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.