|
7 | 7 | from typing import Any |
8 | 8 |
|
9 | 9 | from roborock import B01Props |
10 | | -from roborock.data import HomeDataDevice, HomeDataProduct, Q7MapList, Q7MapListEntry |
| 10 | +from roborock.data import HomeDataDevice, HomeDataProduct, Q7MapList, Q7MapListEntry, Q7RoborockPoint |
11 | 11 | from roborock.data.b01_q7.b01_q7_code_mappings import ( |
12 | 12 | CleanPathPreferenceMapping, |
13 | 13 | CleanRepeatMapping, |
|
35 | 35 | "MapContentTrait", |
36 | 36 | "Q7MapList", |
37 | 37 | "Q7MapListEntry", |
| 38 | + "Q7RoborockPoint", |
38 | 39 | ] |
39 | 40 |
|
40 | 41 |
|
@@ -190,6 +191,33 @@ async def clean_segments(self, segment_ids: list[int]) -> None: |
190 | 191 | }, |
191 | 192 | ) |
192 | 193 |
|
| 194 | + async def clean_zone(self, first_corner: Q7RoborockPoint, second_corner: Q7RoborockPoint) -> None: |
| 195 | + """Clean one rectangular zone given two opposite corners in common Roborock coordinates.""" |
| 196 | + await self.clean_zones([(first_corner, second_corner)]) |
| 197 | + |
| 198 | + async def clean_zones(self, zones: list[tuple[Q7RoborockPoint, Q7RoborockPoint]]) -> None: |
| 199 | + """Clean one or more rectangular zones in a single task. |
| 200 | +
|
| 201 | + Each zone is given by two opposite corners in common Roborock coordinates. |
| 202 | + The device takes the zones as a flat list of rectangle corners in world |
| 203 | + meters (``[x1, y1, x2, y1, x2, y2, x1, y2, ...]``) and needs the zone |
| 204 | + preference type selected first; ``set_zone_clean`` then starts the task. |
| 205 | + """ |
| 206 | + if not zones: |
| 207 | + raise ValueError("at least one zone is required") |
| 208 | + zone_points: list[float] = [] |
| 209 | + for first_corner, second_corner in zones: |
| 210 | + x1, y1 = first_corner.to_world() |
| 211 | + x2, y2 = second_corner.to_world() |
| 212 | + if x1 == x2 or y1 == y2: |
| 213 | + raise ValueError(f"zone corners must span an area: {first_corner}, {second_corner}") |
| 214 | + min_x, max_x = sorted((x1, x2)) |
| 215 | + min_y, max_y = sorted((y1, y2)) |
| 216 | + zone_points += [min_x, min_y, max_x, min_y, max_x, max_y, min_x, max_y] |
| 217 | + await self.send(RoborockB01Q7Methods.SET_PREFERENCE_TYPE, {"prefer_type": CleanTaskTypeMapping.AREA.code}) |
| 218 | + await self.send(RoborockB01Q7Methods.SET_ZONE_POINTS, {"zone_points": zone_points}) |
| 219 | + await self.send(RoborockB01Q7Methods.SET_ZONE_CLEAN, {"ctrl_value": SCDeviceCleanParam.START.code}) |
| 220 | + |
193 | 221 | async def pause_clean(self) -> None: |
194 | 222 | """Pause cleaning.""" |
195 | 223 | await self.send( |
|
0 commit comments