|
42 | 42 | from pyshark.packet.packet import Packet # type: ignore |
43 | 43 |
|
44 | 44 | from roborock import SHORT_MODEL_TO_ENUM, DeviceFeatures, RoborockCommand, RoborockException |
45 | | -from roborock.containers import DeviceData, HomeData, NetworkInfo, RoborockBase, UserData |
| 45 | +from roborock.containers import CombinedMapInfo, DeviceData, HomeData, NetworkInfo, RoborockBase, UserData |
46 | 46 | from roborock.devices.cache import Cache, CacheData |
47 | 47 | from roborock.devices.device import RoborockDevice |
48 | 48 | from roborock.devices.device_manager import DeviceManager, create_device_manager, create_home_data_api |
@@ -116,6 +116,7 @@ class ConnectionCache(RoborockBase): |
116 | 116 | email: str |
117 | 117 | home_data: HomeData | None = None |
118 | 118 | network_info: dict[str, NetworkInfo] | None = None |
| 119 | + home_cache: dict[int, CombinedMapInfo] | None = None |
119 | 120 |
|
120 | 121 |
|
121 | 122 | class DeviceConnectionManager: |
@@ -258,14 +259,21 @@ def finish_session(self) -> None: |
258 | 259 |
|
259 | 260 | async def get(self) -> CacheData: |
260 | 261 | """Get cached value.""" |
| 262 | + _LOGGER.debug("Getting cache data") |
261 | 263 | connection_cache = self.cache_data() |
262 | | - return CacheData(home_data=connection_cache.home_data, network_info=connection_cache.network_info or {}) |
| 264 | + return CacheData( |
| 265 | + home_data=connection_cache.home_data, |
| 266 | + network_info=connection_cache.network_info or {}, |
| 267 | + home_cache=connection_cache.home_cache, |
| 268 | + ) |
263 | 269 |
|
264 | 270 | async def set(self, value: CacheData) -> None: |
265 | 271 | """Set value in the cache.""" |
| 272 | + _LOGGER.debug("Setting cache data") |
266 | 273 | connection_cache = self.cache_data() |
267 | 274 | connection_cache.home_data = value.home_data |
268 | 275 | connection_cache.network_info = value.network_info |
| 276 | + connection_cache.home_cache = value.home_cache |
269 | 277 | self.update(connection_cache) |
270 | 278 |
|
271 | 279 |
|
@@ -533,6 +541,42 @@ async def rooms(ctx, device_id: str): |
533 | 541 | await _display_v1_trait(context, device_id, lambda v1: v1.rooms) |
534 | 542 |
|
535 | 543 |
|
| 544 | +@session.command() |
| 545 | +@click.option("--device_id", required=True) |
| 546 | +@click.option("--refresh", is_flag=True, default=False, help="Refresh status before discovery.") |
| 547 | +@click.pass_context |
| 548 | +@async_command |
| 549 | +async def home(ctx, device_id: str, refresh: bool): |
| 550 | + """Discover and cache home layout (maps and rooms).""" |
| 551 | + context: RoborockContext = ctx.obj |
| 552 | + device_manager = await context.get_device_manager() |
| 553 | + device = await device_manager.get_device(device_id) |
| 554 | + if device.v1_properties is None: |
| 555 | + raise RoborockException(f"Device {device.name} does not support V1 protocol") |
| 556 | + |
| 557 | + # Ensure we have the latest status before discovery |
| 558 | + await device.v1_properties.status.refresh() |
| 559 | + |
| 560 | + home_trait = device.v1_properties.home |
| 561 | + await home_trait.discover_home() |
| 562 | + if refresh: |
| 563 | + await home_trait.refresh() |
| 564 | + |
| 565 | + # Display the discovered home cache |
| 566 | + if home_trait.home_cache: |
| 567 | + cache_summary = { |
| 568 | + map_flag: { |
| 569 | + "name": map_data.name, |
| 570 | + "room_count": len(map_data.rooms), |
| 571 | + "rooms": [{"segment_id": room.segment_id, "name": room.name} for room in map_data.rooms], |
| 572 | + } |
| 573 | + for map_flag, map_data in home_trait.home_cache.items() |
| 574 | + } |
| 575 | + click.echo(dump_json(cache_summary)) |
| 576 | + else: |
| 577 | + click.echo("No maps discovered") |
| 578 | + |
| 579 | + |
536 | 580 | @click.command() |
537 | 581 | @click.option("--device_id", required=True) |
538 | 582 | @click.option("--cmd", required=True) |
@@ -780,6 +824,7 @@ def write_markdown_table(product_features: dict[str, dict[str, any]], all_featur |
780 | 824 | cli.add_command(consumables) |
781 | 825 | cli.add_command(reset_consumable) |
782 | 826 | cli.add_command(rooms) |
| 827 | +cli.add_command(home) |
783 | 828 |
|
784 | 829 |
|
785 | 830 | def main(): |
|
0 commit comments