node-miio 0.6.0 → 0.8.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/README.md +4 -0
- package/dist/cli/commands/roborock/call.d.ts +10 -0
- package/dist/cli/commands/roborock/call.js +34 -0
- package/dist/cli/commands/roborock/call.js.map +1 -0
- package/dist/cli/commands/roborock/devices.d.ts +8 -0
- package/dist/cli/commands/roborock/devices.js +58 -0
- package/dist/cli/commands/roborock/devices.js.map +1 -0
- package/dist/cli/commands/roborock/login.d.ts +7 -0
- package/dist/cli/commands/roborock/login.js +34 -0
- package/dist/cli/commands/roborock/login.js.map +1 -0
- package/dist/cli/commands/roborock/logout.d.ts +4 -0
- package/dist/cli/commands/roborock/logout.js +14 -0
- package/dist/cli/commands/roborock/logout.js.map +1 -0
- package/dist/cli/commands/roborock/map.d.ts +10 -0
- package/dist/cli/commands/roborock/map.js +74 -0
- package/dist/cli/commands/roborock/map.js.map +1 -0
- package/dist/cli/commands/roborock/robot.d.ts +30 -0
- package/dist/cli/commands/roborock/robot.js +61 -0
- package/dist/cli/commands/roborock/robot.js.map +1 -0
- package/dist/cli/commands/roborock/rooms.d.ts +9 -0
- package/dist/cli/commands/roborock/rooms.js +40 -0
- package/dist/cli/commands/roborock/rooms.js.map +1 -0
- package/dist/cli/commands/roborock.d.ts +5 -0
- package/dist/cli/commands/roborock.js +55 -0
- package/dist/cli/commands/roborock.js.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/cloud/client.d.ts +18 -5
- package/dist/lib/cloud/client.js +17 -7
- package/dist/lib/cloud/client.js.map +1 -1
- package/dist/lib/cloud/device_cache.d.ts +38 -0
- package/dist/lib/cloud/device_cache.js +59 -0
- package/dist/lib/cloud/device_cache.js.map +1 -0
- package/dist/lib/cloud/index.d.ts +2 -1
- package/dist/lib/cloud/index.js +4 -1
- package/dist/lib/cloud/index.js.map +1 -1
- package/dist/lib/device_info.d.ts +6 -0
- package/dist/lib/devices/vacuums/vacuum.d.ts +3 -3
- package/dist/lib/devices/vacuums/vacuum.js +13 -3
- package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
- package/dist/lib/devices/vacuums/vacuum_modes.d.ts +2 -0
- package/dist/lib/devices/vacuums/vacuum_modes.js +15 -0
- package/dist/lib/devices/vacuums/vacuum_modes.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/logger.js +1 -1
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/management.d.ts +2 -2
- package/dist/lib/management.js.map +1 -1
- package/dist/lib/roborock/device.d.ts +118 -0
- package/dist/lib/roborock/device.js +273 -0
- package/dist/lib/roborock/device.js.map +1 -0
- package/dist/lib/roborock/errors.d.ts +18 -0
- package/dist/lib/roborock/errors.js +37 -0
- package/dist/lib/roborock/errors.js.map +1 -0
- package/dist/lib/roborock/hawk.d.ts +39 -0
- package/dist/lib/roborock/hawk.js +48 -0
- package/dist/lib/roborock/hawk.js.map +1 -0
- package/dist/lib/roborock/index.d.ts +9 -0
- package/dist/lib/roborock/index.js +36 -0
- package/dist/lib/roborock/index.js.map +1 -0
- package/dist/lib/roborock/local_connection.d.ts +72 -0
- package/dist/lib/roborock/local_connection.js +232 -0
- package/dist/lib/roborock/local_connection.js.map +1 -0
- package/dist/lib/roborock/map_response.d.ts +26 -0
- package/dist/lib/roborock/map_response.js +104 -0
- package/dist/lib/roborock/map_response.js.map +1 -0
- package/dist/lib/roborock/message.d.ts +110 -0
- package/dist/lib/roborock/message.js +313 -0
- package/dist/lib/roborock/message.js.map +1 -0
- package/dist/lib/roborock/mqtt.d.ts +119 -0
- package/dist/lib/roborock/mqtt.js +305 -0
- package/dist/lib/roborock/mqtt.js.map +1 -0
- package/dist/lib/roborock/rooms.d.ts +17 -0
- package/dist/lib/roborock/rooms.js +23 -0
- package/dist/lib/roborock/rooms.js.map +1 -0
- package/dist/lib/roborock/session_store.d.ts +21 -0
- package/dist/lib/roborock/session_store.js +52 -0
- package/dist/lib/roborock/session_store.js.map +1 -0
- package/dist/lib/roborock/web_api.d.ts +142 -0
- package/dist/lib/roborock/web_api.js +334 -0
- package/dist/lib/roborock/web_api.js.map +1 -0
- package/docs/cloud.md +11 -0
- package/docs/roborock.md +91 -0
- package/package.json +2 -1
- package/snapshots/vacuum-specs.json.gz +0 -0
- package/.claude/settings.json +0 -5
- package/.claude/skills/release/SKILL.md +0 -73
- package/AGENTS.md +0 -140
- package/CONTRIBUTING.md +0 -58
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RoborockLocalConnection = exports.ROBOROCK_LOCAL_PORT = void 0;
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
const node_events_1 = require("node:events");
|
|
9
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
const errors_1 = require("./errors");
|
|
12
|
+
const message_1 = require("./message");
|
|
13
|
+
/** The TCP port of the robots' local API */
|
|
14
|
+
exports.ROBOROCK_LOCAL_PORT = 58867;
|
|
15
|
+
const PING_INTERVAL_MS = 10_000;
|
|
16
|
+
/** How long to wait for the answer to a hello before trying the other protocol version */
|
|
17
|
+
const HELLO_TIMEOUT_MS = 4_000;
|
|
18
|
+
/** Unix time in seconds */
|
|
19
|
+
const now = () => Math.floor(Date.now() / 1000);
|
|
20
|
+
const randomInt = (min, max) => node_crypto_1.default.randomInt(min, max);
|
|
21
|
+
/**
|
|
22
|
+
* A local connection to a Roborock robot, over TCP port 58867 (local protocols `1.0` and `L01`).
|
|
23
|
+
*
|
|
24
|
+
* Events: `message` (every message received, e.g. status pushes), `close`.
|
|
25
|
+
*/
|
|
26
|
+
class RoborockLocalConnection extends node_events_1.EventEmitter {
|
|
27
|
+
options;
|
|
28
|
+
session;
|
|
29
|
+
waiting = new Set();
|
|
30
|
+
pingTimer;
|
|
31
|
+
connecting;
|
|
32
|
+
preferredVersion;
|
|
33
|
+
debug;
|
|
34
|
+
seq = 1;
|
|
35
|
+
/** @returns The next message sequence number (the hello is 1) */
|
|
36
|
+
nextSeq() {
|
|
37
|
+
this.seq = this.seq >= 0x7fffffff ? 2 : this.seq + 1;
|
|
38
|
+
return this.seq;
|
|
39
|
+
}
|
|
40
|
+
constructor(options) {
|
|
41
|
+
super();
|
|
42
|
+
this.options = options;
|
|
43
|
+
this.preferredVersion = options.protocolVersion;
|
|
44
|
+
this.debug = (0, logger_1.createDebug)(`miio:roborock:local:${options.address}`, () => options.logger);
|
|
45
|
+
}
|
|
46
|
+
/** Whether the connection is open and the robot answered the hello */
|
|
47
|
+
get connected() {
|
|
48
|
+
return Boolean(this.session && !this.session.socket.destroyed && !this.connecting);
|
|
49
|
+
}
|
|
50
|
+
/** The local protocol version the robot answered to (`undefined` until connected) */
|
|
51
|
+
get protocolVersion() {
|
|
52
|
+
return this.session?.version ?? this.preferredVersion;
|
|
53
|
+
}
|
|
54
|
+
get timeoutMs() {
|
|
55
|
+
return this.options.timeoutMs ?? 10_000;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Connects (if not connected yet) and says hello to the robot.
|
|
59
|
+
*/
|
|
60
|
+
async connect() {
|
|
61
|
+
if (this.connected)
|
|
62
|
+
return;
|
|
63
|
+
this.connecting ??= this.open().finally(() => {
|
|
64
|
+
this.connecting = undefined;
|
|
65
|
+
});
|
|
66
|
+
return this.connecting;
|
|
67
|
+
}
|
|
68
|
+
async open() {
|
|
69
|
+
const versions = this.preferredVersion === "L01" ? ["L01", "1.0"] : ["1.0", "L01"];
|
|
70
|
+
for (const version of versions) {
|
|
71
|
+
const socket = await this.openSocket();
|
|
72
|
+
const session = {
|
|
73
|
+
socket,
|
|
74
|
+
version,
|
|
75
|
+
nonces: { connectNonce: randomInt(10000, 32767) },
|
|
76
|
+
reader: new message_1.LengthPrefixedReader(),
|
|
77
|
+
};
|
|
78
|
+
this.seq = 1;
|
|
79
|
+
this.session = session;
|
|
80
|
+
socket.on("data", (chunk) => this.onData(session, chunk));
|
|
81
|
+
socket.on("error", (err) => this.debug(`Socket error: ${err.message}`));
|
|
82
|
+
socket.on("close", () => this.onClose(session));
|
|
83
|
+
try {
|
|
84
|
+
const response = await this.request({
|
|
85
|
+
version,
|
|
86
|
+
seq: 1,
|
|
87
|
+
random: session.nonces.connectNonce,
|
|
88
|
+
timestamp: now(),
|
|
89
|
+
protocol: message_1.RoborockProtocol.HELLO_REQUEST,
|
|
90
|
+
}, (m) => m.protocol === message_1.RoborockProtocol.HELLO_RESPONSE &&
|
|
91
|
+
m.version === version, Math.min(this.timeoutMs, HELLO_TIMEOUT_MS));
|
|
92
|
+
session.nonces.ackNonce = response.random;
|
|
93
|
+
this.preferredVersion = version;
|
|
94
|
+
this.debug(`Connected (local protocol ${version})`);
|
|
95
|
+
this.startPing();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
this.debug(`No answer to the ${version} hello: ${err.message}`);
|
|
100
|
+
this.session = undefined;
|
|
101
|
+
socket.destroy();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw new errors_1.RoborockError(`The robot at ${this.options.address} didn't answer the hello (local protocols 1.0 and L01)`);
|
|
105
|
+
}
|
|
106
|
+
openSocket() {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
const s = node_net_1.default.connect({
|
|
109
|
+
host: this.options.address,
|
|
110
|
+
port: this.options.port ?? exports.ROBOROCK_LOCAL_PORT,
|
|
111
|
+
timeout: this.timeoutMs,
|
|
112
|
+
});
|
|
113
|
+
s.once("connect", () => {
|
|
114
|
+
s.setTimeout(0);
|
|
115
|
+
resolve(s);
|
|
116
|
+
});
|
|
117
|
+
s.once("timeout", () => {
|
|
118
|
+
s.destroy();
|
|
119
|
+
reject(new errors_1.RoborockError(`Couldn't connect to ${this.options.address}: timed out`));
|
|
120
|
+
});
|
|
121
|
+
s.once("error", (err) => reject(new errors_1.RoborockError(`Couldn't connect to ${this.options.address}: ${err.message}`)));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
startPing() {
|
|
125
|
+
clearInterval(this.pingTimer);
|
|
126
|
+
this.pingTimer = setInterval(() => {
|
|
127
|
+
const version = this.session?.version;
|
|
128
|
+
if (!version)
|
|
129
|
+
return;
|
|
130
|
+
this.request({
|
|
131
|
+
version,
|
|
132
|
+
seq: this.nextSeq(),
|
|
133
|
+
random: randomInt(10000, 99999),
|
|
134
|
+
timestamp: now(),
|
|
135
|
+
protocol: message_1.RoborockProtocol.PING_REQUEST,
|
|
136
|
+
}, (m) => m.protocol === message_1.RoborockProtocol.PING_RESPONSE).catch((err) => {
|
|
137
|
+
this.debug(`Ping failed, closing: ${err.message}`);
|
|
138
|
+
this.close();
|
|
139
|
+
});
|
|
140
|
+
}, PING_INTERVAL_MS);
|
|
141
|
+
this.pingTimer.unref?.();
|
|
142
|
+
}
|
|
143
|
+
onData(session, chunk) {
|
|
144
|
+
for (const frame of session.reader.push(chunk)) {
|
|
145
|
+
let message;
|
|
146
|
+
try {
|
|
147
|
+
message = (0, message_1.decodeMessage)(frame, this.options.localKey, session.nonces);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
this.debug(`Ignoring a message: ${err.message}`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
for (const matcher of this.waiting) {
|
|
154
|
+
if (matcher(message))
|
|
155
|
+
this.waiting.delete(matcher);
|
|
156
|
+
}
|
|
157
|
+
this.emit("message", message);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
onClose(session) {
|
|
161
|
+
if (this.session !== session)
|
|
162
|
+
return;
|
|
163
|
+
this.debug("Disconnected");
|
|
164
|
+
clearInterval(this.pingTimer);
|
|
165
|
+
this.session = undefined;
|
|
166
|
+
this.emit("close");
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Sends a message and waits for the first received message that matches.
|
|
170
|
+
*
|
|
171
|
+
* @param message The message to send
|
|
172
|
+
* @param matches Whether a received message is the response
|
|
173
|
+
* @param timeoutMs How long to wait for the response
|
|
174
|
+
* @returns The response
|
|
175
|
+
*/
|
|
176
|
+
request(message, matches, timeoutMs = this.timeoutMs) {
|
|
177
|
+
const session = this.session;
|
|
178
|
+
if (!session || session.socket.destroyed) {
|
|
179
|
+
return Promise.reject(new errors_1.RoborockError("Not connected"));
|
|
180
|
+
}
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
const matcher = (received) => {
|
|
183
|
+
if (!matches(received))
|
|
184
|
+
return false;
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
resolve(received);
|
|
187
|
+
return true;
|
|
188
|
+
};
|
|
189
|
+
const timer = setTimeout(() => {
|
|
190
|
+
this.waiting.delete(matcher);
|
|
191
|
+
reject(new errors_1.RoborockError(`No response after ${timeoutMs} ms`));
|
|
192
|
+
}, timeoutMs);
|
|
193
|
+
this.waiting.add(matcher);
|
|
194
|
+
session.socket.write((0, message_1.withLengthPrefix)((0, message_1.encodeMessage)(message, this.options.localKey, session.nonces)));
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Calls a method on the robot (the same methods as miIO: `get_status`, `app_start`…).
|
|
199
|
+
*
|
|
200
|
+
* @param method The method
|
|
201
|
+
* @param params The params
|
|
202
|
+
* @returns The result
|
|
203
|
+
*/
|
|
204
|
+
async call(method, params = []) {
|
|
205
|
+
await this.connect();
|
|
206
|
+
const version = this.session?.version ?? "1.0";
|
|
207
|
+
const id = randomInt(10000, 32767);
|
|
208
|
+
const timestamp = now();
|
|
209
|
+
this.debug(`-> ${method} (${id})`, JSON.stringify(params));
|
|
210
|
+
const response = await this.request({
|
|
211
|
+
version,
|
|
212
|
+
seq: this.nextSeq(),
|
|
213
|
+
random: randomInt(10000, 99999),
|
|
214
|
+
timestamp,
|
|
215
|
+
protocol: message_1.RoborockProtocol.GENERAL_REQUEST,
|
|
216
|
+
payload: (0, message_1.rpcPayload)({ id, method, params }, timestamp),
|
|
217
|
+
}, (m) => (0, message_1.rpcResponse)(m)?.id === id);
|
|
218
|
+
// The matcher only accepts messages with an RPC response
|
|
219
|
+
const rpc = (0, message_1.rpcResponse)(response);
|
|
220
|
+
this.debug(`<- ${method} (${id})`, JSON.stringify(rpc.result ?? rpc.error));
|
|
221
|
+
return (0, message_1.rpcResult)(method, rpc);
|
|
222
|
+
}
|
|
223
|
+
/** Closes the connection */
|
|
224
|
+
close() {
|
|
225
|
+
clearInterval(this.pingTimer);
|
|
226
|
+
for (const matcher of this.waiting)
|
|
227
|
+
this.waiting.delete(matcher);
|
|
228
|
+
this.session?.socket.destroy();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.RoborockLocalConnection = RoborockLocalConnection;
|
|
232
|
+
//# sourceMappingURL=local_connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local_connection.js","sourceRoot":"","sources":["../../../src/lib/roborock/local_connection.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AACjC,6CAA2C;AAC3C,wDAA2B;AAE3B,sCAAyD;AAEzD,qCAAyC;AACzC,uCAYmB;AAEnB,4CAA4C;AAC/B,QAAA,mBAAmB,GAAG,KAAK,CAAC;AAEzC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,0FAA0F;AAC1F,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAmB/B,2BAA2B;AAC3B,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAChD,MAAM,SAAS,GAAG,CAA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
|
|
|
1
|
+
import { type RoborockMessage } from "./message";
|
|
2
|
+
export interface MapResponse {
|
|
3
|
+
requestId: number;
|
|
4
|
+
/** The map file (decrypted and decompressed) */
|
|
5
|
+
data: Buffer;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Collects the parts of the map responses and decodes them once complete.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MapResponseAssembler {
|
|
11
|
+
private readonly nonce;
|
|
12
|
+
private readonly endpoint;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
/**
|
|
15
|
+
* @param endpoint The `endpoint` of the requests' security block
|
|
16
|
+
* @param nonce The `nonce` of the requests' security block (the AES key)
|
|
17
|
+
*/
|
|
18
|
+
constructor(endpoint: string, nonce: Buffer);
|
|
19
|
+
/**
|
|
20
|
+
* @param message A received message
|
|
21
|
+
* @returns The map, once all its parts arrived (`undefined` otherwise, or for maps requested by someone else)
|
|
22
|
+
*/
|
|
23
|
+
push(message: RoborockMessage): MapResponse | undefined;
|
|
24
|
+
private isFirstPart;
|
|
25
|
+
private decode;
|
|
26
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MapResponseAssembler = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* The map responses of `get_map_v1` over MQTT (protocols 300/301).
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
* endpoint (8, ASCII) | ? (8) | request id u16 LE | ? (6) | AES-128-CBC(gzip(map file)), key = the request's nonce, IV = 0
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Large maps are split in several messages sharing `random` and `timestamp`, numbered by `seq`: all but the last are
|
|
15
|
+
* protocol 300, the last one 301; only the first part has the header. Parts may arrive out of order.
|
|
16
|
+
*
|
|
17
|
+
* Format documented by python-roborock (Apache-2.0), `roborock/protocols/v1_protocol.py`. No code is copied from it.
|
|
18
|
+
*/
|
|
19
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
20
|
+
const node_zlib_1 = require("node:zlib");
|
|
21
|
+
const errors_1 = require("./errors");
|
|
22
|
+
const message_1 = require("./message");
|
|
23
|
+
const HEADER_LENGTH = 24;
|
|
24
|
+
/** Incomplete multi-part responses kept while waiting for their missing parts */
|
|
25
|
+
const MAX_PENDING = 4;
|
|
26
|
+
/**
|
|
27
|
+
* Collects the parts of the map responses and decodes them once complete.
|
|
28
|
+
*/
|
|
29
|
+
class MapResponseAssembler {
|
|
30
|
+
nonce;
|
|
31
|
+
endpoint;
|
|
32
|
+
pending = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* @param endpoint The `endpoint` of the requests' security block
|
|
35
|
+
* @param nonce The `nonce` of the requests' security block (the AES key)
|
|
36
|
+
*/
|
|
37
|
+
constructor(endpoint, nonce) {
|
|
38
|
+
this.nonce = nonce;
|
|
39
|
+
this.endpoint = Buffer.from(endpoint, "latin1");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @param message A received message
|
|
43
|
+
* @returns The map, once all its parts arrived (`undefined` otherwise, or for maps requested by someone else)
|
|
44
|
+
*/
|
|
45
|
+
push(message) {
|
|
46
|
+
if (message.protocol !== message_1.RoborockProtocol.MAP_RESPONSE &&
|
|
47
|
+
message.protocol !== message_1.RoborockProtocol.MAP_RESPONSE_PART) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const payload = message.payload;
|
|
51
|
+
if (!payload?.length) {
|
|
52
|
+
throw new errors_1.RoborockError("Map response without payload");
|
|
53
|
+
}
|
|
54
|
+
const last = message.protocol === message_1.RoborockProtocol.MAP_RESPONSE;
|
|
55
|
+
const key = `${message.random}:${message.timestamp}`;
|
|
56
|
+
if (last && !this.pending.has(key) && this.isFirstPart(payload)) {
|
|
57
|
+
return this.decode(payload);
|
|
58
|
+
}
|
|
59
|
+
const parts = this.pending.get(key) ?? new Map();
|
|
60
|
+
this.pending.delete(key);
|
|
61
|
+
parts.set(message.seq, { last, payload });
|
|
62
|
+
const ordered = [...parts.entries()].sort(([a], [b]) => a - b);
|
|
63
|
+
const first = ordered[0];
|
|
64
|
+
const lastPart = ordered[ordered.length - 1];
|
|
65
|
+
const complete = lastPart[1].last &&
|
|
66
|
+
lastPart[0] - first[0] === ordered.length - 1 &&
|
|
67
|
+
this.isFirstPart(first[1].payload);
|
|
68
|
+
if (!complete) {
|
|
69
|
+
this.pending.set(key, parts);
|
|
70
|
+
while (this.pending.size > MAX_PENDING) {
|
|
71
|
+
this.pending.delete(this.pending.keys().next().value);
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return this.decode(Buffer.concat(ordered.map(([, part]) => part.payload)));
|
|
76
|
+
}
|
|
77
|
+
isFirstPart(payload) {
|
|
78
|
+
return (payload.length >= this.endpoint.length &&
|
|
79
|
+
payload.subarray(0, this.endpoint.length).equals(this.endpoint));
|
|
80
|
+
}
|
|
81
|
+
decode(payload) {
|
|
82
|
+
if (payload.length < HEADER_LENGTH) {
|
|
83
|
+
throw new errors_1.RoborockError("Map response too short");
|
|
84
|
+
}
|
|
85
|
+
// Another client's map (same account): not ours
|
|
86
|
+
if (!this.isFirstPart(payload))
|
|
87
|
+
return undefined;
|
|
88
|
+
const requestId = payload.readUInt16LE(16);
|
|
89
|
+
let data;
|
|
90
|
+
try {
|
|
91
|
+
const decipher = node_crypto_1.default.createDecipheriv("aes-128-cbc", this.nonce, Buffer.alloc(16));
|
|
92
|
+
data = (0, node_zlib_1.gunzipSync)(Buffer.concat([
|
|
93
|
+
decipher.update(payload.subarray(HEADER_LENGTH)),
|
|
94
|
+
decipher.final(),
|
|
95
|
+
]));
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
throw new errors_1.RoborockError(`Couldn't decode the map: ${err.message}`);
|
|
99
|
+
}
|
|
100
|
+
return { requestId, data };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.MapResponseAssembler = MapResponseAssembler;
|
|
104
|
+
//# sourceMappingURL=map_response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map_response.js","sourceRoot":"","sources":["../../../src/lib/roborock/map_response.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;GAWG;AACH,8DAAiC;AACjC,yCAAuC;AAEvC,qCAAyC;AACzC,uCAAmE;AAEnE,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,iFAAiF;AACjF,MAAM,WAAW,GAAG,CAAC,CAAC;AAQtB;;GAEG;AACH,MAAa,oBAAoB;IAaZ;IAZF,QAAQ,CAAS;IACjB,OAAO,GAAG,IAAI,GAAG,EAG/B,CAAC;IAEJ;;;OAGG;IACH,YACE,QAAgB,EACC,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;QAE9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAwB;QAC3B,IACE,OAAO,CAAC,QAAQ,KAAK,0BAAgB,CAAC,YAAY;YAClD,OAAO,CAAC,QAAQ,KAAK,0BAAgB,CAAC,iBAAiB,EACvD,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,sBAAa,CAAC,8BAA8B,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,KAAK,0BAAgB,CAAC,YAAY,CAAC;QAChE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;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AAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,sBAAa,CACrB,4BAA6B,GAAa,CAAC,OAAO,EAAE,CACrD,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC7B,CAAC;CACF;AA7FD,oDA6FC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** The message types (`protocol` field) */
|
|
2
|
+
export declare const RoborockProtocol: {
|
|
3
|
+
readonly HELLO_REQUEST: 0;
|
|
4
|
+
readonly HELLO_RESPONSE: 1;
|
|
5
|
+
readonly PING_REQUEST: 2;
|
|
6
|
+
readonly PING_RESPONSE: 3;
|
|
7
|
+
/** RPC over the local connection */
|
|
8
|
+
readonly GENERAL_REQUEST: 4;
|
|
9
|
+
readonly GENERAL_RESPONSE: 5;
|
|
10
|
+
/** RPC over MQTT */
|
|
11
|
+
readonly RPC_REQUEST: 101;
|
|
12
|
+
readonly RPC_RESPONSE: 102;
|
|
13
|
+
readonly MAP_RESPONSE_PART: 300;
|
|
14
|
+
readonly MAP_RESPONSE: 301;
|
|
15
|
+
};
|
|
16
|
+
export interface RoborockMessage {
|
|
17
|
+
version: string;
|
|
18
|
+
seq: number;
|
|
19
|
+
random: number;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
protocol: number;
|
|
22
|
+
/** The decrypted payload (usually JSON) */
|
|
23
|
+
payload?: Buffer;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @param timestamp Unix time in seconds
|
|
27
|
+
* @returns The timestamp as 8 hex digits, shuffled the way the robots expect
|
|
28
|
+
*/
|
|
29
|
+
export declare function encodeTimestamp(timestamp: number): string;
|
|
30
|
+
/** The protocol versions of the messages: `1.0` (AES-ECB) or `L01` (AES-GCM, newer local connections) */
|
|
31
|
+
export type RoborockMessageVersion = "1.0" | "L01";
|
|
32
|
+
/**
|
|
33
|
+
* The nonces of an `L01` connection, exchanged in the hello: `connectNonce` is the `random` of our hello,
|
|
34
|
+
* `ackNonce` the `random` of the robot's response. Both are part of every message's authenticated data.
|
|
35
|
+
*/
|
|
36
|
+
export interface L01Nonces {
|
|
37
|
+
connectNonce: number;
|
|
38
|
+
ackNonce?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @param message The message
|
|
42
|
+
* @param localKey The robot's local key
|
|
43
|
+
* @param nonces The connection's nonces (`L01` messages only)
|
|
44
|
+
* @returns The encoded message (without the TCP length prefix)
|
|
45
|
+
*/
|
|
46
|
+
export declare function encodeMessage(message: RoborockMessage, localKey: string, nonces?: L01Nonces): Buffer<ArrayBuffer>;
|
|
47
|
+
/**
|
|
48
|
+
* @param data One encoded message (without the TCP length prefix)
|
|
49
|
+
* @param localKey The robot's local key
|
|
50
|
+
* @param nonces The connection's nonces (`L01` messages only)
|
|
51
|
+
* @returns The message
|
|
52
|
+
*/
|
|
53
|
+
export declare function decodeMessage(data: Buffer, localKey: string, nonces?: L01Nonces): RoborockMessage;
|
|
54
|
+
/**
|
|
55
|
+
* @param message The encoded message
|
|
56
|
+
* @returns The message with its TCP length prefix
|
|
57
|
+
*/
|
|
58
|
+
export declare function withLengthPrefix(message: Buffer): Buffer<ArrayBuffer>;
|
|
59
|
+
/**
|
|
60
|
+
* Splits the TCP stream into messages (length-prefixed).
|
|
61
|
+
*/
|
|
62
|
+
export declare class LengthPrefixedReader {
|
|
63
|
+
private buffer;
|
|
64
|
+
/**
|
|
65
|
+
* @param chunk The data received
|
|
66
|
+
* @returns The complete messages received so far (without their prefix)
|
|
67
|
+
*/
|
|
68
|
+
push(chunk: Buffer): Buffer[];
|
|
69
|
+
}
|
|
70
|
+
/** An RPC request, as sent in the payload (`dps.101`) */
|
|
71
|
+
export interface RoborockRpcRequest {
|
|
72
|
+
id: number;
|
|
73
|
+
method: string;
|
|
74
|
+
params: unknown;
|
|
75
|
+
security?: {
|
|
76
|
+
endpoint: string;
|
|
77
|
+
nonce: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @param request The RPC request
|
|
82
|
+
* @param timestamp Unix time in seconds
|
|
83
|
+
* @returns The payload of an RPC message
|
|
84
|
+
*/
|
|
85
|
+
export declare function rpcPayload(request: RoborockRpcRequest, timestamp: number): Buffer<ArrayBuffer>;
|
|
86
|
+
/**
|
|
87
|
+
* @param message A received message
|
|
88
|
+
* @returns The data points of its payload, by code (`102` = RPC response, `121`… = status pushes)
|
|
89
|
+
*/
|
|
90
|
+
export declare function dataPoints(message: RoborockMessage): Record<string, unknown> | undefined;
|
|
91
|
+
export interface RoborockRpcResponse {
|
|
92
|
+
id: number;
|
|
93
|
+
result?: unknown;
|
|
94
|
+
error?: {
|
|
95
|
+
code?: number;
|
|
96
|
+
message?: string;
|
|
97
|
+
} | string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @param message A received message
|
|
101
|
+
* @returns The RPC response it carries, if any
|
|
102
|
+
*/
|
|
103
|
+
export declare function rpcResponse(message: RoborockMessage): RoborockRpcResponse | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* @param method The method that was called
|
|
106
|
+
* @param rpc Its response
|
|
107
|
+
* @returns The result
|
|
108
|
+
* @throws {RoborockApiError} If the robot returned an error, or doesn't know the method
|
|
109
|
+
*/
|
|
110
|
+
export declare function rpcResult<T>(method: string, rpc: RoborockRpcResponse): T;
|