homebridge-roborock-vacuum 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.5.0
4
+
5
+ - **New (Q10 series)**: Q10 robots (`roborock.vacuum.ss07`, such as the Q10 S5+) can be controlled (#64). They speak their own protocol: a command is a numbered data point that the robot never answers, and its status, map and rooms arrive as pushes. The plugin used to send them the commands of other models, which they ignore, so every command and poll timed out (`Cloud request with id … timed out after 10 seconds`). Start, pause, resume, stop, return to dock, Matter room cleaning and clean modes, state, battery, charging, filter and brush life, and faults now work through the Roborock cloud; see "Q10 series" in the README
6
+ - **Fix (cloud)**: Protocol 301 packets that are not map replies to the plugin, such as the 14-byte cleaning-path packets of Q10 robots, are no longer read as map replies. Each one logged `RangeError: The value of "offset" is out of range` (#64)
7
+
8
+ ## 2.4.1
9
+
10
+ - **Fix (scenes)**: A scene run over the LAN no longer stops when the vacuum refuses the next step right after docking (#63). Some vacuums, such as the S8 MaxV Ultra, report "charging" while the dock is still washing the mop, so the plugin sent the next step too early, the vacuum refused it, and the remaining steps were dropped (`Scene "…" stopped because the robot did not accept it`). A refused step is now sent again every 30 seconds, once the vacuum reports idle, for up to 10 minutes; the log shows `was not accepted; the dock may still be busy` when this happens
11
+ - **Fix (scenes)**: A refused step is no longer counted as started when the dock begins emptying the bin or washing the mop right after it. The plugin then waited for the dock and moved on to the following step, so the rooms of the refused step were silently skipped
12
+
3
13
  ## 2.4.0
4
14
 
5
15
  - **New (Matter)**: Vacuums with several saved floor maps publish every floor with its rooms; Apple Home shows a **Cleaning Map** picker (#62). Each map's rooms are read once while the vacuum is on its dock: the plugin loads the map for a few seconds and then the original one again, and the vacuum does not move. Starting a clean of another floor's rooms loads that map first, like a Roborock scene; the vacuum must already be on that floor. Every room clean first checks the vacuum's own room list, so a room renamed or re-divided in the Roborock app since the last refresh is refused instead of cleaning another segment. A floor without named rooms is published as one area that cleans the whole floor. The first map, and vacuums with a single map, keep their area ids, so existing room selections and automations keep working. See "Multi-floor maps" in the README
package/README.md CHANGED
@@ -34,7 +34,9 @@ This plugin is inspired by and adapted from the [ioBroker.roborock](https://gith
34
34
 
35
35
  The plugin works with vacuums that are on your **Roborock app** account. These models are known to work:
36
36
 
37
- S4, S4 Max, S5 Max, S6, S6 Pure, S6 MaxV, S7, S7 MaxV (Ultra), S7 Pro Ultra, S7 Max Ultra, S8, S8 Pro Ultra, S8 MaxV Ultra, Q5+, Q5 Pro, Q7, Q7 Max, Q8 Max, Qrevo, Qrevo Pro, Qrevo S, Qrevo Curv, Saros 10, and the models `roborock.vacuum.a95`, `roborock.vacuum.a159` and `roborock.vacuum.ss07`.
37
+ S4, S4 Max, S5 Max, S6, S6 Pure, S6 MaxV, S7, S7 MaxV (Ultra), S7 Pro Ultra, S7 Max Ultra, S8, S8 Pro Ultra, S8 MaxV Ultra, Q5+, Q5 Pro, Q7, Q7 Max, Q8 Max, Qrevo, Qrevo Pro, Qrevo S, Qrevo Curv, Saros 10, and the models `roborock.vacuum.a95` and `roborock.vacuum.a159`.
38
+
39
+ The Q10 series (`roborock.vacuum.ss07`, such as the Q10 S5+) is supported through the Roborock cloud; see [Q10 series](#q10-series).
38
40
 
39
41
  Most other vacuums in the Roborock app work as well; which extras (dock mop wash, consumables, clean modes) appear depends on what the model reports. A vacuum that is set up only in the Xiaomi Home app is not on your Roborock account, so the plugin cannot see it.
40
42
 
@@ -151,6 +153,8 @@ answer locally goes over the LAN first, and the cloud is only the fallback:
151
153
  - **Scenes** whose steps are all commands for vacuums connected over the LAN
152
154
  run locally, one step after the other: the next step starts once the
153
155
  vacuum is back on the dock and the dock has finished emptying and washing.
156
+ A step the vacuum refuses, for example while the dock is still washing the
157
+ mop, is sent again every 30 seconds for up to 10 minutes.
154
158
  Stopping or docking the vacuum from Apple Home, starting another scene on
155
159
  it, or restarting Homebridge drops the remaining steps. Other scenes, and
156
160
  scenes whose first step the vacuum does not accept locally, are run by the
@@ -186,6 +190,39 @@ protocol than the one the cloud reports for them. The plugin detects this when
186
190
  it connects and logs `reports protocol 1.0 but answers L01 locally`; nothing
187
191
  needs to be configured.
188
192
 
193
+ ## Q10 series
194
+
195
+ The Q10 series (`roborock.vacuum.ss07`, such as the Q10 S5+) speaks its own
196
+ protocol, and the plugin translates for it. Q10 robots have no local protocol,
197
+ so they are always controlled through the Roborock cloud; local-only mode does
198
+ not apply to them.
199
+
200
+ What works:
201
+
202
+ - Start, pause, resume, stop and return to the dock, over HomeKit and Matter.
203
+ Starting a paused robot resumes its task.
204
+ - State, battery and charging, from the updates the robot pushes. The plugin
205
+ asks it for a full status every polling interval.
206
+ - Room cleaning over Matter. The rooms come from the map the robot sends, so
207
+ they appear once it has sent one after the plugin starts; rooms with a
208
+ default name in the Roborock app (`rr_living_room`) are shown the way the
209
+ app shows them (Living Room).
210
+ - Matter clean modes (vacuum, mop, vacuum & mop). Suction and water levels
211
+ stay as set in the Roborock app.
212
+ - Filter and brush life, from the hours of use the robot reports.
213
+ - Faults that have an Apple Home equivalent, while the robot reports an error.
214
+ Other faults are named in the log.
215
+
216
+ Not available on Q10 robots: find me (Matter Identify), resetting consumables,
217
+ the dock mop-wash switch, multi-floor maps, the room currently being cleaned
218
+ and the Current Room → MQTT telemetry. A command the Q10 has no equivalent for
219
+ is not sent, and the log says so.
220
+
221
+ A Q10 does not answer commands, so a command counts as done once it reaches
222
+ the Roborock cloud; the robot's next status update shows whether it acted on
223
+ it. The Q10 protocol support follows
224
+ [python-roborock](https://github.com/Python-roborock/python-roborock).
225
+
189
226
  ## Dock mop-wash switch
190
227
 
191
228
  On vacuums whose dock can wash the mop (G10, S7 Pro/MaxV Ultra, S7 Max Ultra, S8 Pro Ultra, Q Revo family, …) the plugin adds a switch that starts and stops a dock mop wash:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-roborock-vacuum",
3
3
  "displayName": "Homebridge Roborock Vacuum",
4
- "version": "2.4.0",
4
+ "version": "2.5.0",
5
5
  "description": "Homebridge plugin that brings Roborock robot vacuums to Apple Home over HomeKit or Matter, with local control on your network.",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -0,0 +1,610 @@
1
+ "use strict";
2
+
3
+ // Roborock Q10 series (protocol B01, models roborock.vacuum.ss*, e.g. the
4
+ // Q10 S5+ roborock.vacuum.ss07).
5
+ //
6
+ // B01 is shared by two device families that speak different dialects inside
7
+ // the same encrypted frame. The Q7 series (sc*) wraps a JSON-RPC call in data
8
+ // point 10000. A Q10 understands none of that: it is controlled by writing
9
+ // numbered data points directly, {"dps":{"201":1}}, and it never replies to a
10
+ // write. Its state arrives as data point pushes on protocol 102, and its map
11
+ // and cleaning path as binary packets on protocol 301. There is no local
12
+ // (LAN) protocol, so everything goes through the cloud MQTT broker.
13
+ //
14
+ // The data point numbers, payloads and enums follow python-roborock
15
+ // (roborock/data/b01_q10, roborock/devices/traits/b01/q10), whose commands
16
+ // are marked as verified on ss07 hardware, and the Q10 protocol notes of
17
+ // roborock-q10-cli (DP_DICTIONARY.md, FRAME_ANATOMY.md). The command set
18
+ // matches homebridge-roborock-matter, where it was confirmed on a Q10 S5.
19
+ //
20
+ // This module translates between that dialect and the V1 shapes the rest of
21
+ // the plugin speaks: V1 method names going out, V1 status fields (state,
22
+ // battery, fan_power, ...) coming in. It keeps no state of its own.
23
+
24
+ const DP = {
25
+ FAULT: 90,
26
+ COMMON: 101,
27
+ REQUEST_DPS: 102,
28
+ STATUS: 121,
29
+ BATTERY: 122,
30
+ FAN_LEVEL: 123,
31
+ WATER_LEVEL: 124,
32
+ MAIN_BRUSH_LIFE: 125,
33
+ SIDE_BRUSH_LIFE: 126,
34
+ FILTER_LIFE: 127,
35
+ CLEAN_MODE: 137,
36
+ START_CLEAN: 201,
37
+ START_BACK: 202,
38
+ PAUSE: 204,
39
+ RESUME: 205,
40
+ STOP: 206,
41
+ };
42
+
43
+ // dpStartClean (201) task codes.
44
+ const CLEAN_TASK_WHOLE_HOME = 1;
45
+ const CLEAN_TASK_ROOMS = 2;
46
+ // dpStartBack (202): 5 returns to the dock to charge, as the Roborock app
47
+ // does (1 and 4 also wash the mop or empty the bin on the way).
48
+ const BACK_TO_DOCK_CHARGE = 5;
49
+
50
+ // dpCleanMode (137).
51
+ const CLEAN_MODE_VACUUM_AND_MOP = 1;
52
+ const CLEAN_MODE_VACUUM = 2;
53
+ const CLEAN_MODE_MOP = 3;
54
+
55
+ // V1 values the rest of the plugin uses for suction and water.
56
+ const V1_FAN_OFF = 105;
57
+ const V1_WATER_OFF = 200;
58
+
59
+ // dpFanLevel (123) -> V1 fan_power. Q10: 0 off, 1 quiet, 2 balanced,
60
+ // 3 turbo, 4 max, 8 max+.
61
+ const FAN_LEVEL_TO_V1 = {
62
+ 0: V1_FAN_OFF,
63
+ 1: 101,
64
+ 2: 102,
65
+ 3: 103,
66
+ 4: 104,
67
+ 8: 108,
68
+ };
69
+
70
+ // dpWaterLevel (124) -> V1 water_box_mode. Q10: 0 off, 1 low, 2 medium,
71
+ // 3 high.
72
+ const WATER_LEVEL_TO_V1 = { 0: V1_WATER_OFF, 1: 201, 2: 202, 3: 203 };
73
+
74
+ // dpStatus (121) -> the V1 state with the same meaning. The common states use
75
+ // the V1 numbers already. The Q10 adds sub-states of a running clean (99
76
+ // saving the map, 101 relocating, 102 vacuuming, 103 mopping, 104 vacuuming
77
+ // and mopping, 105 transitioning) and 108 waiting to charge; read as V1
78
+ // numbers, 101 and 103 would mean "offline" and "locked", so they are folded
79
+ // into cleaning (5) and charging (8). 7 is remote control, V1 state 4.
80
+ const STATE_TO_V1 = {
81
+ 2: 2, // sleeping
82
+ 3: 3, // idle
83
+ 5: 5, // cleaning
84
+ 6: 6, // returning to the dock
85
+ 7: 4, // remote control
86
+ 8: 8, // charging
87
+ 10: 10, // paused
88
+ 12: 12, // error
89
+ 14: 14, // updating
90
+ 22: 22, // emptying the bin
91
+ 29: 29, // mapping
92
+ 99: 5, // saving the map
93
+ 101: 5, // relocating
94
+ 102: 5, // vacuuming
95
+ 103: 5, // mopping
96
+ 104: 5, // vacuuming and mopping
97
+ 105: 5, // transitioning
98
+ 108: 8, // waiting to charge
99
+ };
100
+
101
+ // The V1 error state. dpFault lingers after the event that set it (and can
102
+ // read 0 while the robot is in error), so the robot's state decides whether
103
+ // there is a fault at all: one is reported only while the state is "error".
104
+ const V1_STATE_ERROR = 12;
105
+
106
+ // dpFault (90) codes that share a V1 error_code's meaning, so the existing
107
+ // labels and Matter error mapping apply. Most of the low Q10 codes are the
108
+ // V1 numbers.
109
+ const FAULT_TO_V1_ERROR = {
110
+ 1: 1, // lidar blocked -> laser sensor fault
111
+ 2: 2, // bumper stuck -> collision sensor fault
112
+ 3: 3, // robot suspended -> wheel floating
113
+ 4: 4, // cliff sensor error
114
+ 5: 5, // main brush stuck
115
+ 7: 7, // main wheels stuck -> wheel blocked
116
+ 8: 8, // robot trapped -> device stuck
117
+ 9: 9, // check dust bin and filter -> dust bin missing
118
+ 16: 16, // robot tilted -> uneven surface
119
+ 21: 21, // lidar cover obstructed -> laser pressure sensor problem
120
+ 24: 24, // no-go zone detected
121
+ 46: 9, // install the dust bag -> dust bin missing
122
+ 310: 254, // dust bag full -> bin full
123
+ 503: 23, // docking error -> dock problem
124
+ };
125
+
126
+ // dpFault codes that report a step of a normal clean, not a problem: low
127
+ // battery (the robot recharges and resumes), consumable reminders, starting a
128
+ // scheduled clean, clean in progress, clean finished, recharge and resume,
129
+ // "too frequent emptying", positioning and target outcomes, offline warnings.
130
+ const INFORMATIONAL_FAULTS = new Set([
131
+ 0, 12, 301, 302, 303, 304, 400, 407, 501, 502, 556, 569, 570, 588, 589, 591,
132
+ 3001,
133
+ ]);
134
+
135
+ // Names of the dpFault codes for the log (python-roborock YXFault).
136
+ const FAULT_NAMES = {
137
+ 1: "lidar blocked",
138
+ 2: "bumper stuck",
139
+ 3: "robot suspended",
140
+ 4: "cliff sensor error",
141
+ 5: "main brush stuck",
142
+ 7: "main wheels stuck",
143
+ 8: "robot trapped",
144
+ 9: "check the dust bin and filter",
145
+ 12: "low battery",
146
+ 14: "temperature out of range",
147
+ 16: "robot tilted",
148
+ 21: "lidar cover obstructed",
149
+ 24: "no-go zone detected",
150
+ 27: "mopping module stuck",
151
+ 28: "carpet avoidance",
152
+ 29: "cannot cross the carpet",
153
+ 46: "install the dust bag",
154
+ 54: "mop mount fell off",
155
+ 58: "lidar dirty",
156
+ 310: "dust bag full",
157
+ 503: "docking error",
158
+ 707: "clean the carpet sensors",
159
+ 1002: "robot error reset",
160
+ };
161
+
162
+ // Remaining-life fields for dpMainBrushLife/dpSideBrushLife/dpFilterLife,
163
+ // which report hours of use (rated 300/200/150 h, as on V1 robots).
164
+ const CONSUMABLE_DPS = {
165
+ main_brush: DP.MAIN_BRUSH_LIFE,
166
+ side_brush: DP.SIDE_BRUSH_LIFE,
167
+ filter: DP.FILTER_LIFE,
168
+ };
169
+
170
+ /** Whether a device with this protocol version and model is a Q10. */
171
+ function isQ10Model(pv, model) {
172
+ if (pv !== "B01" || typeof model !== "string") {
173
+ return false;
174
+ }
175
+ return model.split(".").pop().startsWith("ss");
176
+ }
177
+
178
+ function firstParam(params) {
179
+ return Array.isArray(params) ? params[0] : params;
180
+ }
181
+
182
+ // Room ids from app_segment_clean's [{ segments: [...] }] or a plain list.
183
+ function segmentIds(params) {
184
+ const first = firstParam(params);
185
+ const ids =
186
+ first && typeof first === "object" && Array.isArray(first.segments)
187
+ ? first.segments
188
+ : Array.isArray(params)
189
+ ? params
190
+ : [];
191
+ return ids.map(Number).filter((id) => Number.isInteger(id) && id >= 0);
192
+ }
193
+
194
+ /**
195
+ * The data point write for a V1 method, as { dp, value }, or null when the
196
+ * Q10 has no equivalent (every read included: a Q10 never answers).
197
+ * context.paused: the robot is paused, so app_start resumes the paused task
198
+ * instead of starting a new whole-home clean.
199
+ */
200
+ function encodeCommand(method, params, context = {}) {
201
+ switch (method) {
202
+ case "app_start":
203
+ return context.paused
204
+ ? { dp: DP.RESUME, value: 0 }
205
+ : { dp: DP.START_CLEAN, value: CLEAN_TASK_WHOLE_HOME };
206
+ case "resume_segment_clean":
207
+ return { dp: DP.RESUME, value: 0 };
208
+ case "app_pause":
209
+ return { dp: DP.PAUSE, value: 0 };
210
+ case "app_stop":
211
+ return { dp: DP.STOP, value: 0 };
212
+ case "app_charge":
213
+ return { dp: DP.START_BACK, value: BACK_TO_DOCK_CHARGE };
214
+ case "app_segment_clean": {
215
+ const rooms = segmentIds(params);
216
+ if (rooms.length === 0) {
217
+ return null;
218
+ }
219
+ // "clean_paramters" is the firmware's own spelling; it accepts no other.
220
+ return {
221
+ dp: DP.START_CLEAN,
222
+ value: { cmd: CLEAN_TASK_ROOMS, clean_paramters: rooms },
223
+ };
224
+ }
225
+ default:
226
+ return null;
227
+ }
228
+ }
229
+
230
+ /**
231
+ * The data point write for a Matter clean mode given in V1 terms: suction off
232
+ * (105) means mop only, water off (200) or no water level (a robot without
233
+ * mop support) means vacuum only, both on means vacuum and mop. Returns null
234
+ * when no suction level is given either.
235
+ *
236
+ * Only the mode is written. A Q10 keeps its suction and water levels per mode,
237
+ * and the levels the Matter accessory passes along are V1 defaults whenever
238
+ * the current mode had that motor off, so writing them would overwrite the
239
+ * levels set in the Roborock app.
240
+ */
241
+ function encodeCleanMode(fanPower, waterBoxMode) {
242
+ const fan = fanPower === undefined ? undefined : Number(fanPower);
243
+ const water = waterBoxMode === undefined ? undefined : Number(waterBoxMode);
244
+
245
+ if (fan === V1_FAN_OFF) {
246
+ return { dp: DP.CLEAN_MODE, value: CLEAN_MODE_MOP };
247
+ }
248
+ if (fan === undefined) {
249
+ return null;
250
+ }
251
+ if (water === undefined || water === V1_WATER_OFF) {
252
+ return { dp: DP.CLEAN_MODE, value: CLEAN_MODE_VACUUM };
253
+ }
254
+ return { dp: DP.CLEAN_MODE, value: CLEAN_MODE_VACUUM_AND_MOP };
255
+ }
256
+
257
+ /** The MQTT payload for a data point write. 0 is a real value. */
258
+ function encodePayload(dp, value) {
259
+ return JSON.stringify({
260
+ dps: { [String(dp)]: value === undefined || value === null ? {} : value },
261
+ });
262
+ }
263
+
264
+ /**
265
+ * A data point map with the nested dpCommon (101) values lifted to the top
266
+ * level, where python-roborock reads them too (the fault arrives there).
267
+ */
268
+ function flattenDps(dps) {
269
+ if (!dps || typeof dps !== "object") {
270
+ return {};
271
+ }
272
+ const flat = { ...dps };
273
+ const common = flat[String(DP.COMMON)];
274
+ delete flat[String(DP.COMMON)];
275
+ if (common && typeof common === "object" && !Array.isArray(common)) {
276
+ Object.assign(flat, common);
277
+ }
278
+ return flat;
279
+ }
280
+
281
+ function numberAt(dps, dp) {
282
+ const value = dps[String(dp)];
283
+ if (value === undefined || value === null || value === "") {
284
+ return undefined;
285
+ }
286
+ const number = Number(value);
287
+ return Number.isFinite(number) ? number : undefined;
288
+ }
289
+
290
+ /**
291
+ * V1 status fields for a flattened data point map (see flattenDps). Pass the
292
+ * robot's accumulated data points: a push often carries one or two, and
293
+ * suction and water depend on the clean mode as well.
294
+ *
295
+ * Returns { status, unknownState, unmappedFault }. status holds only the
296
+ * fields that could be read faithfully; unknownState and unmappedFault carry
297
+ * a code the plugin has no translation for, for the log.
298
+ */
299
+ function toV1Status(dps, options = {}) {
300
+ const status = {};
301
+ let unknownState;
302
+ let unmappedFault;
303
+
304
+ const rawState = numberAt(dps, DP.STATUS);
305
+ if (rawState !== undefined) {
306
+ const state = STATE_TO_V1[rawState];
307
+ if (state === undefined) {
308
+ unknownState = rawState;
309
+ } else {
310
+ status.state = state;
311
+ // Emptying the bin happens in the dock, but whether the robot charges
312
+ // meanwhile is not reported.
313
+ if (state !== 22) {
314
+ status.charge_status = state === 8 ? 1 : 0;
315
+ }
316
+ }
317
+ }
318
+
319
+ const battery = numberAt(dps, DP.BATTERY);
320
+ if (battery !== undefined) {
321
+ status.battery = battery;
322
+ }
323
+
324
+ const mode = numberAt(dps, DP.CLEAN_MODE);
325
+ const fanLevel = numberAt(dps, DP.FAN_LEVEL);
326
+ const waterLevel = numberAt(dps, DP.WATER_LEVEL);
327
+ if (mode === CLEAN_MODE_MOP) {
328
+ status.fan_power = V1_FAN_OFF;
329
+ } else if (
330
+ fanLevel !== undefined &&
331
+ FAN_LEVEL_TO_V1[fanLevel] !== undefined
332
+ ) {
333
+ status.fan_power = FAN_LEVEL_TO_V1[fanLevel];
334
+ }
335
+ if (mode === CLEAN_MODE_VACUUM) {
336
+ status.water_box_mode = V1_WATER_OFF;
337
+ } else if (
338
+ waterLevel !== undefined &&
339
+ WATER_LEVEL_TO_V1[waterLevel] !== undefined
340
+ ) {
341
+ status.water_box_mode = WATER_LEVEL_TO_V1[waterLevel];
342
+ }
343
+
344
+ if (status.state !== undefined) {
345
+ const fault = numberAt(dps, DP.FAULT);
346
+ if (
347
+ status.state !== V1_STATE_ERROR ||
348
+ fault === undefined ||
349
+ INFORMATIONAL_FAULTS.has(fault)
350
+ ) {
351
+ status.error_code = 0;
352
+ } else if (FAULT_TO_V1_ERROR[fault] !== undefined) {
353
+ status.error_code = FAULT_TO_V1_ERROR[fault];
354
+ } else {
355
+ status.error_code = 0;
356
+ unmappedFault = fault;
357
+ }
358
+ }
359
+
360
+ const ratedHours = options.ratedHours || {};
361
+ for (const [name, dp] of Object.entries(CONSUMABLE_DPS)) {
362
+ const hoursUsed = numberAt(dps, dp);
363
+ const rated = ratedHours[name];
364
+ if (hoursUsed !== undefined && rated > 0) {
365
+ status[`${name}_life`] = Math.max(
366
+ 0,
367
+ Math.round(100 - (hoursUsed / rated) * 100)
368
+ );
369
+ }
370
+ }
371
+
372
+ return { status, unknownState, unmappedFault };
373
+ }
374
+
375
+ /** A readable name for a dpFault code. */
376
+ function describeFault(code) {
377
+ return FAULT_NAMES[code] || `fault ${code}`;
378
+ }
379
+
380
+ // Current-map packet (protocol 301, marker 01 01): map id u32 BE at 2, grid
381
+ // width and height u16 BE at 7 and 9, the LZ4 block length u16 BE at 27 and
382
+ // the block from 29. Inflated, it holds width * height grid cells followed by
383
+ // 01 <room count> and one 47-byte record per room: id u16 BE at 0, name
384
+ // length at 26, UTF-8 name from 27. Other markers (02 01 cleaning path,
385
+ // 03 01 clean record, 04 01 saved map) carry no room list.
386
+ const MAP_ID_OFFSET = 2;
387
+ const MAP_WIDTH_OFFSET = 7;
388
+ const MAP_HEIGHT_OFFSET = 9;
389
+ const MAP_BLOCK_LENGTH_OFFSET = 27;
390
+ const MAP_BLOCK_OFFSET = 29;
391
+ const ROOM_RECORD_LENGTH = 47;
392
+ const ROOM_NAME_LENGTH_OFFSET = 26;
393
+ const ROOM_NAME_OFFSET = 27;
394
+ const MAX_ROOMS = 32;
395
+ const MAX_GRID_CELLS = 16000000;
396
+
397
+ /**
398
+ * Inflate a raw LZ4 block (no frame header). Throws on a malformed block or
399
+ * one that would grow past maxOutput bytes.
400
+ */
401
+ function lz4BlockDecompress(input, maxOutput) {
402
+ let output = Buffer.alloc(
403
+ Math.min(maxOutput, Math.max(64, input.length * 4))
404
+ );
405
+ let outLength = 0;
406
+ let position = 0;
407
+
408
+ const ensure = (extra) => {
409
+ const needed = outLength + extra;
410
+ if (needed > maxOutput) {
411
+ throw new Error("LZ4 block is larger than expected");
412
+ }
413
+ if (needed > output.length) {
414
+ const grown = Buffer.alloc(
415
+ Math.min(maxOutput, Math.max(needed, output.length * 2))
416
+ );
417
+ output.copy(grown, 0, 0, outLength);
418
+ output = grown;
419
+ }
420
+ };
421
+ const readLength = (length) => {
422
+ if (length !== 15) {
423
+ return length;
424
+ }
425
+ for (;;) {
426
+ if (position >= input.length) {
427
+ throw new Error("LZ4 block ends inside a length");
428
+ }
429
+ const byte = input[position++];
430
+ length += byte;
431
+ if (byte !== 255) {
432
+ return length;
433
+ }
434
+ }
435
+ };
436
+
437
+ for (;;) {
438
+ if (position >= input.length) {
439
+ throw new Error("LZ4 block ends before a sequence");
440
+ }
441
+ const token = input[position++];
442
+ const literals = readLength(token >> 4);
443
+ if (position + literals > input.length) {
444
+ throw new Error("LZ4 block ends inside its literals");
445
+ }
446
+ ensure(literals);
447
+ input.copy(output, outLength, position, position + literals);
448
+ outLength += literals;
449
+ position += literals;
450
+
451
+ // The last sequence carries literals only.
452
+ if (position === input.length) {
453
+ return output.subarray(0, outLength);
454
+ }
455
+
456
+ if (position + 2 > input.length) {
457
+ throw new Error("LZ4 block ends inside a match offset");
458
+ }
459
+ const offset = input[position] | (input[position + 1] << 8);
460
+ position += 2;
461
+ if (offset === 0 || offset > outLength) {
462
+ throw new Error("LZ4 block has an invalid match offset");
463
+ }
464
+ const matchLength = readLength(token & 0x0f) + 4;
465
+ ensure(matchLength);
466
+ // Byte by byte: a match may overlap the bytes it produces.
467
+ for (let i = 0; i < matchLength; i++) {
468
+ output[outLength] = output[outLength - offset];
469
+ outLength++;
470
+ }
471
+ }
472
+ }
473
+
474
+ function isRoomSection(section, count) {
475
+ return (
476
+ section.length === 2 + count * ROOM_RECORD_LENGTH &&
477
+ section[0] === 1 &&
478
+ section[1] === count
479
+ );
480
+ }
481
+
482
+ // The room records follow the width * height grid. Older firmware leaves the
483
+ // height empty; then the split is found from the record count.
484
+ function findRoomSection(layout, width, height) {
485
+ if (height > 0 && width * height <= layout.length) {
486
+ const section = layout.subarray(width * height);
487
+ if (section.length >= 2 && isRoomSection(section, section[1])) {
488
+ return section;
489
+ }
490
+ }
491
+ // Most rooms first, so two grid bytes that happen to read 01 00 are not
492
+ // taken for an empty room list ahead of the real records.
493
+ for (let count = MAX_ROOMS; count >= 0; count--) {
494
+ const gridLength = layout.length - (2 + count * ROOM_RECORD_LENGTH);
495
+ if (gridLength > 0 && gridLength % width === 0) {
496
+ const section = layout.subarray(gridLength);
497
+ if (isRoomSection(section, count)) {
498
+ return section;
499
+ }
500
+ }
501
+ }
502
+ return null;
503
+ }
504
+
505
+ // Firmware default names look like "rr_living_room"; the Roborock app shows
506
+ // them as "Living Room". Names the user typed are kept as they are.
507
+ function roomName(rawName, id) {
508
+ const name = rawName.replace(/\0+$/, "").trim();
509
+ if (!name) {
510
+ return `Room ${id}`;
511
+ }
512
+ if (!name.startsWith("rr_")) {
513
+ return name;
514
+ }
515
+ const words = name.slice(3).split("_").filter(Boolean);
516
+ if (words.length === 0) {
517
+ return `Room ${id}`;
518
+ }
519
+ return words
520
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
521
+ .join(" ");
522
+ }
523
+
524
+ /**
525
+ * The rooms of a current-map packet as { mapId, rooms: [{ id, name }] }, or
526
+ * null for any other protocol 301 packet. Throws on a malformed map packet.
527
+ */
528
+ function parseMapRooms(payload) {
529
+ if (payload.length < 2 || payload[0] !== 1 || payload[1] !== 1) {
530
+ return null;
531
+ }
532
+ if (payload.length < MAP_BLOCK_OFFSET) {
533
+ throw new Error(`map packet too short (${payload.length} bytes)`);
534
+ }
535
+
536
+ const mapId = payload.readUInt32BE(MAP_ID_OFFSET);
537
+ const width = payload.readUInt16BE(MAP_WIDTH_OFFSET);
538
+ const height = payload.readUInt16BE(MAP_HEIGHT_OFFSET);
539
+ if (width === 0 || width * height > MAX_GRID_CELLS) {
540
+ throw new Error(`map packet has invalid dimensions ${width}x${height}`);
541
+ }
542
+ const blockLength = payload.readUInt16BE(MAP_BLOCK_LENGTH_OFFSET);
543
+ const blockEnd = MAP_BLOCK_OFFSET + blockLength;
544
+ if (blockLength === 0 || blockEnd > payload.length) {
545
+ throw new Error("map packet has an invalid layout length");
546
+ }
547
+
548
+ const layout = lz4BlockDecompress(
549
+ payload.subarray(MAP_BLOCK_OFFSET, blockEnd),
550
+ MAX_GRID_CELLS + 2 + MAX_ROOMS * ROOM_RECORD_LENGTH
551
+ );
552
+ const section = findRoomSection(layout, width, height);
553
+ if (!section) {
554
+ throw new Error("map packet has no room records");
555
+ }
556
+
557
+ const records = [];
558
+ for (let index = 0; index < section[1]; index++) {
559
+ const record = section.subarray(
560
+ 2 + index * ROOM_RECORD_LENGTH,
561
+ 2 + (index + 1) * ROOM_RECORD_LENGTH
562
+ );
563
+ const id = record.readUInt16BE(0);
564
+ const nameLength = Math.min(
565
+ record[ROOM_NAME_LENGTH_OFFSET],
566
+ ROOM_RECORD_LENGTH - ROOM_NAME_OFFSET
567
+ );
568
+ const name = roomName(
569
+ record
570
+ .subarray(ROOM_NAME_OFFSET, ROOM_NAME_OFFSET + nameLength)
571
+ .toString("utf8"),
572
+ id
573
+ );
574
+ records.push({ id, name });
575
+ }
576
+
577
+ // Apple Home needs distinct names: a repeated name gets the first numeric
578
+ // suffix no other room has ("Bedroom 2", or "Bedroom 3" when a room is
579
+ // already called "Bedroom 2").
580
+ const used = new Set(records.map((room) => room.name));
581
+ const given = new Set();
582
+ const rooms = records.map(({ id, name }) => {
583
+ if (!given.has(name)) {
584
+ given.add(name);
585
+ return { id, name };
586
+ }
587
+ let suffix = 2;
588
+ while (used.has(`${name} ${suffix}`)) {
589
+ suffix++;
590
+ }
591
+ const unique = `${name} ${suffix}`;
592
+ used.add(unique);
593
+ given.add(unique);
594
+ return { id, name: unique };
595
+ });
596
+ return { mapId, rooms };
597
+ }
598
+
599
+ module.exports = {
600
+ DP,
601
+ isQ10Model,
602
+ encodeCommand,
603
+ encodeCleanMode,
604
+ encodePayload,
605
+ flattenDps,
606
+ toV1Status,
607
+ describeFault,
608
+ parseMapRooms,
609
+ lz4BlockDecompress,
610
+ };
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ const b01Q10 = require("./b01Q10");
4
+
3
5
  const requestTimeout = 10000; // 10s
4
6
 
5
7
  class messageQueueHandler {
@@ -10,6 +12,13 @@ class messageQueueHandler {
10
12
  }
11
13
 
12
14
  async sendRequest(duid, method, params, secure = false, photo = false) {
15
+ if (
16
+ typeof this.adapter.isQ10Device === "function" &&
17
+ this.adapter.isQ10Device(duid)
18
+ ) {
19
+ return this.sendQ10Request(duid, method, params);
20
+ }
21
+
13
22
  const remoteConnection = await this.adapter.isRemoteDevice(duid);
14
23
  const mqttConnectionState = this.adapter.rr_mqtt_connector.isConnected();
15
24
  const localConnectionState = this.adapter.localConnector.isConnected(duid);
@@ -71,6 +80,65 @@ class messageQueueHandler {
71
80
  }
72
81
  }
73
82
 
83
+ // A V1 request for a Q10 robot, sent as the data point write that does the
84
+ // same thing (see lib/b01Q10.js). A method the Q10 has no equivalent for,
85
+ // which includes every read, is refused without sending anything.
86
+ async sendQ10Request(duid, method, params) {
87
+ const paused =
88
+ method === "app_start" &&
89
+ Number(this.adapter.getVacuumDeviceStatus(duid, "state")) === 10;
90
+ const write = b01Q10.encodeCommand(method, params, { paused });
91
+ if (!write) {
92
+ const error = new Error(
93
+ `${method} is not available on Q10-series robots, so it was not sent to ${duid}.`
94
+ );
95
+ error.code = "ERR_Q10_UNSUPPORTED";
96
+ throw error;
97
+ }
98
+ return this.sendQ10Write(duid, write.dp, write.value);
99
+ }
100
+
101
+ // Publish one Q10 data point write over the cloud. A Q10 never replies to a
102
+ // write, so this resolves once the write is handed to the MQTT client; the
103
+ // robot's next status push shows whether it acted on it.
104
+ async sendQ10Write(duid, dp, value) {
105
+ if (!(await this.adapter.onlineChecker(duid))) {
106
+ this.adapter.log.debug(
107
+ `Device ${duid} offline. Not sending Q10 data point ${dp}.`
108
+ );
109
+ const error = new Error(`${duid} is offline, so it was not sent.`);
110
+ error.code = "ERR_Q10_NOT_SENT";
111
+ throw error;
112
+ }
113
+ if (!this.adapter.rr_mqtt_connector.isConnected()) {
114
+ this.adapter.log.debug(
115
+ `Cloud connection not available. Not sending Q10 data point ${dp}.`
116
+ );
117
+ const error = new Error(
118
+ "The Roborock cloud connection is not available, so it was not sent."
119
+ );
120
+ error.code = "ERR_Q10_NOT_SENT";
121
+ throw error;
122
+ }
123
+
124
+ const payload = b01Q10.encodePayload(dp, value);
125
+ const roborockMessage = await this.adapter.message.buildRoborockMessage(
126
+ duid,
127
+ 101,
128
+ Math.floor(Date.now() / 1000),
129
+ payload
130
+ );
131
+ if (!roborockMessage) {
132
+ throw new Error(`Failed to build the Q10 message for ${duid}.`);
133
+ }
134
+
135
+ this.adapter.rr_mqtt_connector.sendMessage(duid, roborockMessage);
136
+ this.adapter.log.debug(
137
+ `Sent Q10 data point write ${payload} to ${duid} over the cloud. Q10 robots do not reply to writes.`
138
+ );
139
+ return "ok";
140
+ }
141
+
74
142
  // Scene items: local connection only, never retried over the cloud, so a
75
143
  // lost reply cannot start the same item twice.
76
144
  sendLocalRequest(duid, method, params) {
@@ -5,8 +5,13 @@ const crypto = require("crypto");
5
5
  const zlib = require("zlib");
6
6
 
7
7
  // Protocol 301 header (little-endian): endpoint(15, NUL-padded)
8
- // unknown(1) id(2) unknown(6).
8
+ // unknown(1) id(2) unknown(6). Returns null when the payload is too short to
9
+ // carry one: B01 Q10 robots (roborock.vacuum.ss07) push their own binary map
10
+ // and live-trace packets on protocol 301, and an empty trace is 14 bytes.
9
11
  function parse301Header(payload) {
12
+ if (payload.length < 24) {
13
+ return null;
14
+ }
10
15
  return {
11
16
  endpoint: payload.toString("utf8", 0, 15).replace(/\0+$/, ""),
12
17
  id: payload.readUInt16LE(16),
@@ -199,6 +204,29 @@ class roborock_mqtt_connector {
199
204
  pending.resolve(dps.result);
200
205
  }
201
206
 
207
+ // Q10 robots push data points on protocol 102 and map packets on protocol
208
+ // 301, neither in the V1 layout handled in initMQTT_Message (see
209
+ // lib/b01Q10.js).
210
+ handleQ10Message(duid, data) {
211
+ if (data.protocol == 301) {
212
+ this.adapter.handleQ10MapPacket(duid, data.payload);
213
+ return;
214
+ }
215
+
216
+ let parsed;
217
+ try {
218
+ parsed = JSON.parse(data.payload.toString("utf8"));
219
+ } catch (error) {
220
+ this.adapter.log.debug(
221
+ `Unreadable Q10 message from ${duid}: ${error.message}`
222
+ );
223
+ return;
224
+ }
225
+ if (parsed && parsed.dps && typeof parsed.dps === "object") {
226
+ this.adapter.handleQ10Push(duid, parsed.dps);
227
+ }
228
+ }
229
+
202
230
  async initMQTT_Message() {
203
231
  this.adapter.log.info(`MQTT initialized`);
204
232
 
@@ -220,6 +248,15 @@ class roborock_mqtt_connector {
220
248
  if (!data) {
221
249
  return;
222
250
  }
251
+
252
+ if (
253
+ (data.protocol == 102 || data.protocol == 301) &&
254
+ typeof this.adapter.isQ10Device === "function" &&
255
+ this.adapter.isQ10Device(duid)
256
+ ) {
257
+ this.handleQ10Message(duid, data);
258
+ return;
259
+ }
223
260
  // this.adapter.log.debug(`MESSAGE RECEIVED for duid ${duid} with key: ${this.adapter.localKeys.get(duid)} data: ${JSON.stringify(data)} raw: ${JSON.stringify(mqttMessageParser.parse(message))} message: ${message}`);
224
261
  // this.adapter.log.debug(`MESSAGE RECEIVED for duid ${duid} with key: ${this.adapter.localKeys.get(duid)} data: ${JSON.stringify(data.toString("hex"))} message: ${message}`);
225
262
  // this.adapter.log.debug(`MESSAGE RECEIVED for duid ${duid} with key: ${this.adapter.localKeys.get(duid)} data: ${JSON.stringify(data)}`);
@@ -326,7 +363,11 @@ class roborock_mqtt_connector {
326
363
  );
327
364
  resolve(data.payload.slice(56));
328
365
  }
329
- } else if (endpoint.startsWith(data2.endpoint)) {
366
+ } else if (
367
+ data2 &&
368
+ data2.endpoint &&
369
+ endpoint.startsWith(data2.endpoint)
370
+ ) {
330
371
  const iv = Buffer.alloc(16, 0);
331
372
  const decipher = crypto.createDecipheriv(
332
373
  "aes-128-cbc",
@@ -358,6 +399,10 @@ class roborock_mqtt_connector {
358
399
  resolve(decompressed);
359
400
  }
360
401
  });
402
+ } else {
403
+ this.adapter.log.debug(
404
+ `Ignoring protocol 301 message for ${duid} (${data.payload.length} bytes); it is not a map response to this client.`
405
+ );
361
406
  }
362
407
  }
363
408
  } else if (data.protocol == 500) {
@@ -14,6 +14,13 @@ const DOCKED_STATES = [8, 100];
14
14
  // Emptying the dust bin, washing the mop (23, alias 25), going to wash it:
15
15
  // the dock is still busy and the next item waits.
16
16
  const DOCK_BUSY_STATES = [22, 23, 25, 26];
17
+ // The dock's own work, which also follows the end of a clean.
18
+ const DOCK_WORK_STATES = [22, 23, 25];
19
+ // Some robots report charging while the dock still washes the mop, and refuse
20
+ // the next item until it is done (#63). A refused item is sent again once the
21
+ // robot reports idle, for up to RETRY_TIMEOUT.
22
+ const RETRY_INTERVAL = 30 * 1000;
23
+ const RETRY_TIMEOUT = 10 * 60 * 1000;
17
24
 
18
25
  class sceneRunner {
19
26
  constructor(adapter) {
@@ -124,8 +131,14 @@ class sceneRunner {
124
131
 
125
132
  async continue(run) {
126
133
  for (let index = 0; index < run.items.length; index++) {
127
- if (index > 0 && !(await this.startItem(run, index)) && !run.cancelled) {
128
- this.stop(run, index, "the robot did not accept it");
134
+ if (index > 0 && !(await this.startNextItem(run, index))) {
135
+ this.stop(
136
+ run,
137
+ index,
138
+ run.cancelled
139
+ ? "it was cancelled"
140
+ : `the robot did not accept it within ${RETRY_TIMEOUT / 60000} minutes`
141
+ );
129
142
  return;
130
143
  }
131
144
 
@@ -140,10 +153,60 @@ class sceneRunner {
140
153
  this.adapter.log.info(`Scene "${run.name}" finished.`);
141
154
  }
142
155
 
156
+ // Send an item after the first one, again and again while the robot refuses
157
+ // it. Resolves false when the robot did not accept it in time or the run was
158
+ // cancelled.
159
+ async startNextItem(run, index) {
160
+ const item = run.items[index];
161
+ const deadline = Date.now() + RETRY_TIMEOUT;
162
+ for (let attempt = 1; ; attempt++) {
163
+ if (await this.startItem(run, index)) {
164
+ return true;
165
+ }
166
+ if (run.cancelled) {
167
+ return false;
168
+ }
169
+
170
+ const label = `Scene "${run.name}" item ${index + 1} (${item.method})`;
171
+ if (attempt === 1) {
172
+ this.adapter.log.info(
173
+ `${label} was not accepted; the dock may still be busy. Trying again every ${RETRY_INTERVAL / 1000} s for up to ${RETRY_TIMEOUT / 60000} minutes.`
174
+ );
175
+ } else {
176
+ this.adapter.log.debug(
177
+ `${label} was not accepted (attempt ${attempt}).`
178
+ );
179
+ }
180
+ if (!(await this.waitUntilIdle(run, item.duid, deadline))) {
181
+ return false;
182
+ }
183
+ }
184
+ }
185
+
186
+ // Resolves true once a fresh status shows the robot neither cleaning nor
187
+ // busy at the dock, or false at the deadline or when the run was cancelled.
188
+ async waitUntilIdle(run, duid, deadline) {
189
+ while (Date.now() < deadline) {
190
+ await this.sleep(run, RETRY_INTERVAL);
191
+ if (run.cancelled) {
192
+ return false;
193
+ }
194
+ const fresh = await this.adapter.pollStatus(duid);
195
+ if (run.cancelled) {
196
+ return false;
197
+ }
198
+ if (fresh && !this.isBusy(duid)) {
199
+ return true;
200
+ }
201
+ }
202
+ return false;
203
+ }
204
+
143
205
  // Send one item. A reply other than "ok" (a rejection, a timeout, a lost
144
- // reply) counts as started only when a fresh status shows the robot busy
145
- // and it was not busy before, so a scene never falls back to the cloud for
146
- // an item the robot already runs, nor adopts an unrelated clean.
206
+ // reply) counts as started only when a fresh status shows a clean that was
207
+ // not running before, so a scene never falls back to the cloud for an item
208
+ // the robot already runs, nor adopts an unrelated clean or the dock's work
209
+ // after the previous item.
147
210
  async startItem(run, index) {
148
211
  const item = run.items[index];
149
212
  const wasBusy = this.isBusy(item.duid);
@@ -168,7 +231,7 @@ class sceneRunner {
168
231
  return (
169
232
  (await this.adapter.pollStatus(item.duid)) &&
170
233
  !wasBusy &&
171
- this.isBusy(item.duid)
234
+ this.isRunning(item.duid)
172
235
  );
173
236
  }
174
237
 
@@ -230,6 +293,16 @@ class sceneRunner {
230
293
  );
231
294
  }
232
295
 
296
+ // A clean is running: an unfinished one (in_cleaning) or a cleaning state
297
+ // other than the dock's own work.
298
+ isRunning(duid) {
299
+ const state = this.status(duid, "state");
300
+ return (
301
+ this.status(duid, "in_cleaning") > 0 ||
302
+ (this.adapter.isCleaning(state) && !DOCK_WORK_STATES.includes(state))
303
+ );
304
+ }
305
+
233
306
  // Log the items a stopped run did not send, from index on.
234
307
  stop(run, index, reason) {
235
308
  const skipped = run.items
@@ -17,6 +17,7 @@ const deviceFeatures = require("./lib/deviceFeatures").deviceFeatures;
17
17
  const messageQueueHandler =
18
18
  require("./lib/messageQueueHandler").messageQueueHandler;
19
19
  const { sceneRunner, DOCKED_STATES } = require("./lib/sceneRunner");
20
+ const b01Q10 = require("./lib/b01Q10");
20
21
  const mqtt = require("mqtt");
21
22
 
22
23
  // Schema ids of the status fields in spontaneous status broadcasts
@@ -172,6 +173,13 @@ class Roborock {
172
173
  // deviceStatus snapshot while fresh — see getLiveStatus.
173
174
  this.liveStatus = new Map();
174
175
 
176
+ // Q10 robots (see lib/b01Q10.js): the data points each one has pushed,
177
+ // accumulated, since a push often carries only one or two of them; when
178
+ // each one last sent anything; and the log notices already given once.
179
+ this.q10Dps = new Map();
180
+ this.q10LastMessageAt = new Map();
181
+ this.q10Notices = new Set();
182
+
175
183
  this.localDevices = {};
176
184
  this.remoteDevices = new Set();
177
185
 
@@ -958,6 +966,12 @@ class Roborock {
958
966
  const duid = device;
959
967
  const ip = this.localDevices[device];
960
968
 
969
+ // Q10 robots have no local protocol; they are reached over the cloud.
970
+ if (this.isQ10Device(duid)) {
971
+ this.log.debug(`Not connecting locally to Q10 robot ${duid}.`);
972
+ continue;
973
+ }
974
+
961
975
  await this.localConnector.createClient(duid, ip);
962
976
  }
963
977
 
@@ -1165,7 +1179,7 @@ class Roborock {
1165
1179
  async getNetworkInfo() {
1166
1180
  for (const device of this.devices) {
1167
1181
  const duid = device.duid;
1168
- if (!this.hasInitializedVacuum(duid)) {
1182
+ if (!this.hasInitializedVacuum(duid) || this.isQ10Device(duid)) {
1169
1183
  continue;
1170
1184
  }
1171
1185
 
@@ -1267,8 +1281,11 @@ class Roborock {
1267
1281
  // telemetry (its own seconds-based gating lives in vacuum.getParameter).
1268
1282
  // Without that feature the interval would fire 86400 no-ops per device
1269
1283
  // per day, so it is not created at all.
1284
+ // A Q10 has no get_status to tick.
1270
1285
  const roomMqttEnabled = !!(
1271
- this.config.currentRoomMqtt && this.config.currentRoomMqtt.enabled
1286
+ this.config.currentRoomMqtt &&
1287
+ this.config.currentRoomMqtt.enabled &&
1288
+ !this.isQ10Device(duid)
1272
1289
  );
1273
1290
  if (roomMqttEnabled && !vacuum.getStatusIntervalHandle) {
1274
1291
  vacuum.getStatusIntervalHandle = this.setInterval(
@@ -1637,6 +1654,13 @@ class Roborock {
1637
1654
  async updateDataMinimumData(duid, vacuum, robotModel) {
1638
1655
  this.log.debug(`Latest data requested`);
1639
1656
 
1657
+ // A Q10 answers none of the V1 reads below; it is asked to push its
1658
+ // status (and its map) instead.
1659
+ if (this.isQ10Device(duid)) {
1660
+ await this.requestQ10Status(duid);
1661
+ return;
1662
+ }
1663
+
1640
1664
  if (this.isSupportedVacuumModel(robotModel)) {
1641
1665
  await this.pollStatus(duid);
1642
1666
 
@@ -1656,7 +1680,6 @@ class Roborock {
1656
1680
  case "roborock.vacuum.a140":
1657
1681
  case "roborock.vacuum.a95":
1658
1682
  case "roborock.vacuum.a159":
1659
- case "roborock.vacuum.ss07":
1660
1683
  //do nothing
1661
1684
  break;
1662
1685
  case "roborock.vacuum.s6":
@@ -1685,6 +1708,10 @@ class Roborock {
1685
1708
  }
1686
1709
 
1687
1710
  async updateDataExtraData(duid, vacuum) {
1711
+ if (this.isQ10Device(duid)) {
1712
+ return;
1713
+ }
1714
+
1688
1715
  try {
1689
1716
  await this.pollOptional(duid, vacuum, "get_fw_features");
1690
1717
  } catch (error) {
@@ -2075,6 +2102,16 @@ class Roborock {
2075
2102
  return;
2076
2103
  }
2077
2104
 
2105
+ // A command the Q10 has no equivalent for was not sent; say so plainly.
2106
+ if (error.code === "ERR_Q10_UNSUPPORTED") {
2107
+ this.log.info(error.message);
2108
+ return;
2109
+ }
2110
+ if (error.code === "ERR_Q10_NOT_SENT") {
2111
+ this.log.warn(`${attribute} for ${duid}: ${error.message}`);
2112
+ return;
2113
+ }
2114
+
2078
2115
  const errorText = error.toString();
2079
2116
  const isTransient =
2080
2117
  errorText.includes("retry") ||
@@ -2366,6 +2403,22 @@ class Roborock {
2366
2403
  return;
2367
2404
  }
2368
2405
 
2406
+ // A Q10 has its own clean-mode data point next to suction and water.
2407
+ if (this.isQ10Device(duid)) {
2408
+ const write = b01Q10.encodeCleanMode(
2409
+ parameters && parameters.fan_power,
2410
+ parameters && parameters.water_box_mode
2411
+ );
2412
+ if (write) {
2413
+ await this.messageQueueHandler.sendQ10Write(
2414
+ duid,
2415
+ write.dp,
2416
+ write.value
2417
+ );
2418
+ }
2419
+ return;
2420
+ }
2421
+
2369
2422
  if (parameters && parameters.fan_power !== undefined) {
2370
2423
  await vacuum.command(duid, "set_custom_mode", parameters.fan_power);
2371
2424
  }
@@ -2955,9 +3008,7 @@ class Roborock {
2955
3008
  return;
2956
3009
  }
2957
3010
 
2958
- const model = this.getProductAttribute(duid, "model");
2959
- const ratedHours =
2960
- CONSUMABLE_LIFE_HOURS[model] || CONSUMABLE_LIFE_HOURS.default;
3011
+ const ratedHours = this.getConsumableRatedHours(duid);
2961
3012
  const life = {};
2962
3013
  for (const [name, hours] of Object.entries(ratedHours)) {
2963
3014
  const workTime = consumables[`${name}_work_time`];
@@ -3010,6 +3061,171 @@ class Roborock {
3010
3061
  this.recordLiveStatus(duid, status);
3011
3062
  }
3012
3063
 
3064
+ // Rated consumable life in hours for a robot's model.
3065
+ getConsumableRatedHours(duid) {
3066
+ const model = this.getProductAttribute(duid, "model");
3067
+ return CONSUMABLE_LIFE_HOURS[model] || CONSUMABLE_LIFE_HOURS.default;
3068
+ }
3069
+
3070
+ // A Q10-series robot (protocol B01, model ss*); see lib/b01Q10.js.
3071
+ isQ10Device(duid) {
3072
+ const device = this.getVacuumDeviceData(duid);
3073
+ if (!device || device.pv !== "B01") {
3074
+ return false;
3075
+ }
3076
+ const products = this.products || this.getParsedHomeData()?.products || [];
3077
+ const product = products.find((product) => product.id == device.productId);
3078
+ return b01Q10.isQ10Model(device.pv, product && product.model);
3079
+ }
3080
+
3081
+ describeRobot(duid) {
3082
+ const name = this.vacuums[duid] && this.vacuums[duid].name;
3083
+ return name ? `${name} (${duid})` : duid;
3084
+ }
3085
+
3086
+ // Log a Q10 notice at info level once per run.
3087
+ noteQ10Once(key, message) {
3088
+ if (this.q10Notices.has(key)) {
3089
+ return;
3090
+ }
3091
+ this.q10Notices.add(key);
3092
+ this.log.info(message);
3093
+ }
3094
+
3095
+ // Ask a Q10 to push its full status and its current map (dpRequestDps): it
3096
+ // has no status read. A request that brings nothing back from the robot
3097
+ // within 10 s counts toward the stalled-cloud-session check, as a timed-out
3098
+ // V1 cloud request does. Nothing is sent while the robot is offline.
3099
+ async requestQ10Status(duid) {
3100
+ const requestedAt = Date.now();
3101
+ try {
3102
+ await this.messageQueueHandler.sendQ10Write(
3103
+ duid,
3104
+ b01Q10.DP.REQUEST_DPS,
3105
+ {}
3106
+ );
3107
+ } catch (error) {
3108
+ this.log.debug(
3109
+ `Status request for ${this.describeRobot(duid)} was not sent: ${(error && error.message) || "no cloud connection"}`
3110
+ );
3111
+ return;
3112
+ }
3113
+
3114
+ this.noteQ10Once(
3115
+ `status:${duid}`,
3116
+ `${this.describeRobot(duid)} is a Q10-series robot. It is controlled over the Roborock cloud and has no status read, so the plugin asks it to push its status every ${this.updateInterval} s and follows what it pushes.`
3117
+ );
3118
+
3119
+ const timer = this.setTimeout(() => {
3120
+ if ((this.q10LastMessageAt.get(duid) || 0) < requestedAt) {
3121
+ this.log.debug(
3122
+ `${this.describeRobot(duid)} pushed nothing within 10 s of a status request.`
3123
+ );
3124
+ this.recordCloudTimeout();
3125
+ }
3126
+ }, 10000);
3127
+ if (timer && typeof timer.unref === "function") {
3128
+ timer.unref();
3129
+ }
3130
+ }
3131
+
3132
+ // A Q10 data point push (protocol 102). It is folded into what the robot
3133
+ // pushed before, translated to V1 status fields, recorded as live status
3134
+ // and passed to the accessories.
3135
+ handleQ10Push(duid, dps) {
3136
+ if (!dps || typeof dps !== "object") {
3137
+ return;
3138
+ }
3139
+
3140
+ this.q10LastMessageAt.set(duid, Date.now());
3141
+ const previous = this.q10Dps.get(duid) || {};
3142
+ const pushed = b01Q10.flattenDps(dps);
3143
+ const merged = { ...previous, ...pushed };
3144
+ // dpFault keeps its value after an error is cleared. Once the robot
3145
+ // leaves the error state, forget it, so a later error is not reported
3146
+ // with the old fault before the robot pushes the new one.
3147
+ const fault = String(b01Q10.DP.FAULT);
3148
+ const state = String(b01Q10.DP.STATUS);
3149
+ if (
3150
+ Number(previous[state]) === 12 &&
3151
+ Number(merged[state]) !== 12 &&
3152
+ pushed[fault] === undefined
3153
+ ) {
3154
+ delete merged[fault];
3155
+ }
3156
+ this.q10Dps.set(duid, merged);
3157
+
3158
+ const { status, unknownState, unmappedFault } = b01Q10.toV1Status(merged, {
3159
+ ratedHours: this.getConsumableRatedHours(duid),
3160
+ });
3161
+ this.log.debug(
3162
+ `Q10 push from ${duid}: ${JSON.stringify(dps)} -> ${JSON.stringify(status)}`
3163
+ );
3164
+
3165
+ if (unknownState !== undefined) {
3166
+ this.noteQ10Once(
3167
+ `state:${duid}:${unknownState}`,
3168
+ `${this.describeRobot(duid)} reports state ${unknownState}, which the plugin does not know yet; Apple Home keeps the previous state. Please report it in the plugin's GitHub issues.`
3169
+ );
3170
+ }
3171
+ if (unmappedFault !== undefined) {
3172
+ this.noteQ10Once(
3173
+ `fault:${duid}:${unmappedFault}`,
3174
+ `${this.describeRobot(duid)} reports fault ${unmappedFault} (${b01Q10.describeFault(unmappedFault)}), which has no Apple Home equivalent; check the Roborock app.`
3175
+ );
3176
+ }
3177
+
3178
+ if (Object.keys(status).length === 0) {
3179
+ return;
3180
+ }
3181
+ this.recordLiveStatus(duid, status);
3182
+ if (this.deviceNotify) {
3183
+ this.deviceNotify("CloudMessage", status, duid);
3184
+ }
3185
+ }
3186
+
3187
+ // A Q10 map or cleaning-path packet (protocol 301). The current map carries
3188
+ // the room list, which feeds the Matter rooms and room cleaning.
3189
+ handleQ10MapPacket(duid, payload) {
3190
+ this.q10LastMessageAt.set(duid, Date.now());
3191
+ const marker = payload.subarray(0, 2).toString("hex");
3192
+ let map;
3193
+ try {
3194
+ map = b01Q10.parseMapRooms(payload);
3195
+ } catch (error) {
3196
+ this.log.debug(
3197
+ `Q10 map packet ${marker} from ${duid} (${payload.length} bytes) could not be read: ${error.message}`
3198
+ );
3199
+ return;
3200
+ }
3201
+
3202
+ this.log.debug(
3203
+ `Q10 protocol 301 packet ${marker} from ${duid} (${payload.length} bytes)${map ? ` with ${map.rooms.length} room(s)` : ""}.`
3204
+ );
3205
+ if (!map) {
3206
+ return;
3207
+ }
3208
+
3209
+ const names = {};
3210
+ for (const room of map.rooms) {
3211
+ names[room.id] = room.name;
3212
+ }
3213
+ if (
3214
+ JSON.stringify(this.segmentRoomNames[duid] || null) ===
3215
+ JSON.stringify(names)
3216
+ ) {
3217
+ return;
3218
+ }
3219
+
3220
+ this.segmentRoomNames[duid] = names;
3221
+ this.log.info(
3222
+ `Rooms of ${this.describeRobot(duid)}: ${map.rooms.map((room) => `${room.name} (${room.id})`).join(", ") || "none, the map is not divided into rooms"}.`
3223
+ );
3224
+ if (this.deviceNotify) {
3225
+ this.deviceNotify("CloudMessage", {}, duid);
3226
+ }
3227
+ }
3228
+
3013
3229
  // A live status field, or undefined when unknown or stale. Values older
3014
3230
  // than three poll intervals (polling stops while a device is offline) fall
3015
3231
  // back to the HomeData snapshot.
@@ -3028,6 +3244,16 @@ class Roborock {
3028
3244
  return liveValue;
3029
3245
  }
3030
3246
 
3247
+ // A Q10's HomeData snapshot holds its own data points, in its own units.
3248
+ if (this.isQ10Device(duid)) {
3249
+ const device = this.getVacuumDeviceData(duid);
3250
+ const { status } = b01Q10.toV1Status(
3251
+ b01Q10.flattenDps(device && device.deviceStatus),
3252
+ { ratedHours: this.getConsumableRatedHours(duid) }
3253
+ );
3254
+ return status[property] !== undefined ? status[property] : "";
3255
+ }
3256
+
3031
3257
  const propertyID = this.getVacuumSchemaId(duid, property);
3032
3258
 
3033
3259
  if (propertyID == null) {