node-miio 0.7.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/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/roborock.md +91 -0
- package/package.json +2 -1
- package/snapshots/vacuum-specs.json.gz +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
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.RoborockMqttConnection = exports.RoborockMqttSession = void 0;
|
|
7
|
+
exports.mqttParams = mqttParams;
|
|
8
|
+
/**
|
|
9
|
+
* The MQTT connection of a Roborock account: the cloud path to its robots (what the Roborock app uses away from home).
|
|
10
|
+
*
|
|
11
|
+
* - Broker: `rriot.r.m` (e.g. `ssl://mqtt-eu-3.roborock.com:8883`). Username `md5(u:k)[2:10]`, password `md5(s:k)[16:]`.
|
|
12
|
+
* - Topics: requests to `rr/m/i/{u}/{username}/{duid}`, responses and pushes from `rr/m/o/{u}/{username}/{duid}`.
|
|
13
|
+
* - Messages: the same `1.0` messages as the local connection, without the length prefix, as `RPC_REQUEST` (101) with a
|
|
14
|
+
* `security` block (`endpoint`, `nonce`: the nonce encrypts the maps sent back).
|
|
15
|
+
*
|
|
16
|
+
* Documented by python-roborock (Apache-2.0), `roborock/protocol.py` and `roborock/devices/transport/mqtt_channel.py`.
|
|
17
|
+
* No code is copied from it.
|
|
18
|
+
*/
|
|
19
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
20
|
+
const node_events_1 = require("node:events");
|
|
21
|
+
const logger_1 = require("../logger");
|
|
22
|
+
const errors_1 = require("./errors");
|
|
23
|
+
const map_response_1 = require("./map_response");
|
|
24
|
+
const message_1 = require("./message");
|
|
25
|
+
const md5hex = (value) => node_crypto_1.default.createHash("md5").update(value).digest("hex");
|
|
26
|
+
/**
|
|
27
|
+
* Connects with mqtt.js, loaded on first use. Its typings need DOM/worker types, so it's loaded untyped: only
|
|
28
|
+
* `connectAsync` is used, through {@link MqttClientLike}.
|
|
29
|
+
*
|
|
30
|
+
* @param url The broker URL
|
|
31
|
+
* @param options The connection options
|
|
32
|
+
* @returns The client
|
|
33
|
+
*/
|
|
34
|
+
const defaultConnect = async (url, options) => {
|
|
35
|
+
const moduleName = "mqtt";
|
|
36
|
+
const mqtt = (await import(moduleName));
|
|
37
|
+
return mqtt.connectAsync(url, options);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @param rriot The account's `rriot` credentials
|
|
41
|
+
* @returns The broker URL and credentials
|
|
42
|
+
*/
|
|
43
|
+
function mqttParams(rriot) {
|
|
44
|
+
const url = new URL(rriot.r.m);
|
|
45
|
+
const tls = url.protocol === "ssl:" || url.protocol === "mqtts:";
|
|
46
|
+
return {
|
|
47
|
+
url: `${tls ? "mqtts" : "mqtt"}://${url.hostname}:${url.port || (tls ? 8883 : 1883)}`,
|
|
48
|
+
username: md5hex(`${rriot.u}:${rriot.k}`).slice(2, 10),
|
|
49
|
+
password: md5hex(`${rriot.s}:${rriot.k}`).slice(16),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The MQTT connection of an account, shared by its robots.
|
|
54
|
+
*/
|
|
55
|
+
class RoborockMqttSession {
|
|
56
|
+
rriot;
|
|
57
|
+
options;
|
|
58
|
+
client;
|
|
59
|
+
handlers = new Map();
|
|
60
|
+
params;
|
|
61
|
+
debug;
|
|
62
|
+
constructor(rriot, options = {}) {
|
|
63
|
+
this.rriot = rriot;
|
|
64
|
+
this.options = options;
|
|
65
|
+
this.params = mqttParams(rriot);
|
|
66
|
+
this.debug = (0, logger_1.createDebug)("miio:roborock:mqtt", () => options.logger);
|
|
67
|
+
}
|
|
68
|
+
topic(direction, duid) {
|
|
69
|
+
return `rr/m/${direction}/${this.rriot.u}/${this.params.username}/${duid}`;
|
|
70
|
+
}
|
|
71
|
+
connect() {
|
|
72
|
+
this.client ??= (async () => {
|
|
73
|
+
const connect = this.options.connect ?? defaultConnect;
|
|
74
|
+
this.debug(`Connecting to ${this.params.url}`);
|
|
75
|
+
const client = await connect(this.params.url, {
|
|
76
|
+
username: this.params.username,
|
|
77
|
+
password: this.params.password,
|
|
78
|
+
clientId: node_crypto_1.default.randomBytes(8).toString("hex"),
|
|
79
|
+
connectTimeout: this.options.timeoutMs ?? 15_000,
|
|
80
|
+
reconnectPeriod: 10_000,
|
|
81
|
+
keepalive: 60,
|
|
82
|
+
});
|
|
83
|
+
client.on("message", (topic, payload) => {
|
|
84
|
+
for (const handler of this.handlers.get(topic) ?? [])
|
|
85
|
+
handler(payload);
|
|
86
|
+
});
|
|
87
|
+
client.on("connect", () => {
|
|
88
|
+
// After a reconnection: subscribe again
|
|
89
|
+
for (const topic of this.handlers.keys()) {
|
|
90
|
+
client.subscribeAsync(topic).catch(() => { });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return client;
|
|
94
|
+
})().catch((err) => {
|
|
95
|
+
this.client = undefined;
|
|
96
|
+
throw new errors_1.RoborockError(`Couldn't connect to Roborock's MQTT server: ${err.message}`);
|
|
97
|
+
});
|
|
98
|
+
return this.client;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @param duid The robot's ID
|
|
102
|
+
* @param handler Called with every message the robot sends
|
|
103
|
+
* @returns Unsubscribes
|
|
104
|
+
*/
|
|
105
|
+
async subscribe(duid, handler) {
|
|
106
|
+
const client = await this.connect();
|
|
107
|
+
const topic = this.topic("o", duid);
|
|
108
|
+
let handlers = this.handlers.get(topic);
|
|
109
|
+
if (!handlers) {
|
|
110
|
+
handlers = new Set();
|
|
111
|
+
this.handlers.set(topic, handlers);
|
|
112
|
+
await client.subscribeAsync(topic);
|
|
113
|
+
}
|
|
114
|
+
handlers.add(handler);
|
|
115
|
+
return async () => {
|
|
116
|
+
handlers.delete(handler);
|
|
117
|
+
if (handlers.size === 0 && this.handlers.get(topic) === handlers) {
|
|
118
|
+
this.handlers.delete(topic);
|
|
119
|
+
await client.unsubscribeAsync(topic).catch(() => { });
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @param duid The robot's ID
|
|
125
|
+
* @param payload The encoded message
|
|
126
|
+
*/
|
|
127
|
+
async publish(duid, payload) {
|
|
128
|
+
const client = await this.connect();
|
|
129
|
+
await client.publishAsync(this.topic("i", duid), payload);
|
|
130
|
+
}
|
|
131
|
+
/** The `endpoint` of the requests' security block: identifies this account's requests in the map responses */
|
|
132
|
+
get endpoint() {
|
|
133
|
+
return node_crypto_1.default
|
|
134
|
+
.createHash("md5")
|
|
135
|
+
.update(this.rriot.k)
|
|
136
|
+
.digest()
|
|
137
|
+
.subarray(8, 14)
|
|
138
|
+
.toString("base64");
|
|
139
|
+
}
|
|
140
|
+
/** Closes the connection */
|
|
141
|
+
async close() {
|
|
142
|
+
const client = this.client;
|
|
143
|
+
this.client = undefined;
|
|
144
|
+
this.handlers.clear();
|
|
145
|
+
await (await client?.catch(() => undefined))?.endAsync();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.RoborockMqttSession = RoborockMqttSession;
|
|
149
|
+
/** Unix time in seconds */
|
|
150
|
+
const now = () => Math.floor(Date.now() / 1000);
|
|
151
|
+
/**
|
|
152
|
+
* A robot over the account's MQTT connection.
|
|
153
|
+
*
|
|
154
|
+
* Events: `message` (every message received, e.g. status pushes).
|
|
155
|
+
*/
|
|
156
|
+
class RoborockMqttConnection extends node_events_1.EventEmitter {
|
|
157
|
+
session;
|
|
158
|
+
options;
|
|
159
|
+
unsubscribe;
|
|
160
|
+
waiting = new Set();
|
|
161
|
+
seq = 0;
|
|
162
|
+
/** Encrypts the maps sent back (map responses come later) */
|
|
163
|
+
nonce = node_crypto_1.default.randomBytes(16);
|
|
164
|
+
debug;
|
|
165
|
+
constructor(session, options) {
|
|
166
|
+
super();
|
|
167
|
+
this.session = session;
|
|
168
|
+
this.options = options;
|
|
169
|
+
this.debug = (0, logger_1.createDebug)(`miio:roborock:mqtt:${options.duid}`, () => options.logger);
|
|
170
|
+
}
|
|
171
|
+
get timeoutMs() {
|
|
172
|
+
return this.options.timeoutMs ?? 10_000;
|
|
173
|
+
}
|
|
174
|
+
subscribed() {
|
|
175
|
+
this.unsubscribe ??= this.session
|
|
176
|
+
.subscribe(this.options.duid, (payload) => this.onPayload(payload))
|
|
177
|
+
.catch((err) => {
|
|
178
|
+
this.unsubscribe = undefined;
|
|
179
|
+
throw err;
|
|
180
|
+
});
|
|
181
|
+
return this.unsubscribe;
|
|
182
|
+
}
|
|
183
|
+
onPayload(payload) {
|
|
184
|
+
let message;
|
|
185
|
+
try {
|
|
186
|
+
message = (0, message_1.decodeMessage)(payload, this.options.localKey);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
this.debug(`Ignoring a message: ${err.message}`);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
for (const matcher of this.waiting) {
|
|
193
|
+
if (matcher(message))
|
|
194
|
+
this.waiting.delete(matcher);
|
|
195
|
+
}
|
|
196
|
+
this.emit("message", message);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Sends an RPC request and waits for the first received message for which `accept` returns a value.
|
|
200
|
+
*
|
|
201
|
+
* @param method The method
|
|
202
|
+
* @param params The params
|
|
203
|
+
* @param accept Given the request ID, returns the function that extracts the response from the received messages
|
|
204
|
+
* @param timeoutMs How long to wait
|
|
205
|
+
* @returns The response
|
|
206
|
+
*/
|
|
207
|
+
async request(method, params, accept, timeoutMs = this.timeoutMs) {
|
|
208
|
+
await this.subscribed();
|
|
209
|
+
const id = node_crypto_1.default.randomInt(10000, 32767);
|
|
210
|
+
const timestamp = now();
|
|
211
|
+
this.seq = this.seq >= 0x7fffffff ? 1 : this.seq + 1;
|
|
212
|
+
const message = (0, message_1.encodeMessage)({
|
|
213
|
+
version: "1.0",
|
|
214
|
+
seq: this.seq,
|
|
215
|
+
random: node_crypto_1.default.randomInt(10000, 99999),
|
|
216
|
+
timestamp,
|
|
217
|
+
protocol: message_1.RoborockProtocol.RPC_REQUEST,
|
|
218
|
+
payload: (0, message_1.rpcPayload)({
|
|
219
|
+
id,
|
|
220
|
+
method,
|
|
221
|
+
params,
|
|
222
|
+
security: {
|
|
223
|
+
endpoint: this.session.endpoint,
|
|
224
|
+
nonce: this.nonce.toString("hex"),
|
|
225
|
+
},
|
|
226
|
+
}, timestamp),
|
|
227
|
+
}, this.options.localKey);
|
|
228
|
+
this.debug(`-> ${method} (${id})`, JSON.stringify(params));
|
|
229
|
+
const extract = accept(id);
|
|
230
|
+
return new Promise((resolve, reject) => {
|
|
231
|
+
const matcher = (received) => {
|
|
232
|
+
let value;
|
|
233
|
+
try {
|
|
234
|
+
value = extract(received);
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
clearTimeout(timer);
|
|
238
|
+
reject(err);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
if (value === undefined)
|
|
242
|
+
return false;
|
|
243
|
+
clearTimeout(timer);
|
|
244
|
+
resolve(value);
|
|
245
|
+
return true;
|
|
246
|
+
};
|
|
247
|
+
const timer = setTimeout(() => {
|
|
248
|
+
this.waiting.delete(matcher);
|
|
249
|
+
reject(new errors_1.RoborockError(`No response to ${method} over MQTT after ${timeoutMs} ms`));
|
|
250
|
+
}, timeoutMs);
|
|
251
|
+
this.waiting.add(matcher);
|
|
252
|
+
this.session.publish(this.options.duid, message).catch((err) => {
|
|
253
|
+
clearTimeout(timer);
|
|
254
|
+
this.waiting.delete(matcher);
|
|
255
|
+
reject(err);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Calls a method on the robot (the same methods as miIO: `get_status`, `app_start`…).
|
|
261
|
+
*
|
|
262
|
+
* @param method The method
|
|
263
|
+
* @param params The params
|
|
264
|
+
* @returns The result
|
|
265
|
+
*/
|
|
266
|
+
async call(method, params = []) {
|
|
267
|
+
const rpc = await this.request(method, params, (id) => (received) => {
|
|
268
|
+
const response = (0, message_1.rpcResponse)(received);
|
|
269
|
+
return response?.id === id ? response : undefined;
|
|
270
|
+
});
|
|
271
|
+
this.debug(`<- ${method}`, JSON.stringify(rpc.result ?? rpc.error));
|
|
272
|
+
return (0, message_1.rpcResult)(method, rpc);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Downloads the current map (`get_map_v1`). The robot sends it in protocol 300/301 messages, encrypted with this
|
|
276
|
+
* connection's {@link nonce}.
|
|
277
|
+
*
|
|
278
|
+
* @param timeoutMs How long to wait for the map (default 30s)
|
|
279
|
+
* @returns The map file (`rr` format: parse it with `parseRoborockMap`)
|
|
280
|
+
*/
|
|
281
|
+
async getMapData(timeoutMs = 30_000) {
|
|
282
|
+
const assembler = new map_response_1.MapResponseAssembler(this.session.endpoint, this.nonce);
|
|
283
|
+
const map = await this.request("get_map_v1", [], (id) => (received) => {
|
|
284
|
+
// The robot may answer the RPC with an error (e.g. no map yet)
|
|
285
|
+
const rpc = (0, message_1.rpcResponse)(received);
|
|
286
|
+
if (rpc?.id === id && rpc.error !== undefined) {
|
|
287
|
+
(0, message_1.rpcResult)("get_map_v1", rpc);
|
|
288
|
+
}
|
|
289
|
+
const response = assembler.push(received);
|
|
290
|
+
return response?.requestId === id ? response.data : undefined;
|
|
291
|
+
}, timeoutMs);
|
|
292
|
+
this.debug(`<- get_map_v1: ${map.length} bytes`);
|
|
293
|
+
return map;
|
|
294
|
+
}
|
|
295
|
+
/** Stops listening to the robot (the account's session stays open) */
|
|
296
|
+
async close() {
|
|
297
|
+
for (const matcher of this.waiting)
|
|
298
|
+
this.waiting.delete(matcher);
|
|
299
|
+
const unsubscribe = this.unsubscribe;
|
|
300
|
+
this.unsubscribe = undefined;
|
|
301
|
+
await (await unsubscribe?.catch(() => undefined))?.();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.RoborockMqttConnection = RoborockMqttConnection;
|
|
305
|
+
//# sourceMappingURL=mqtt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mqtt.js","sourceRoot":"","sources":["../../../src/lib/roborock/mqtt.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C5B,YAAY,EACZ,EAAE,EACF,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnB,+DAA+D;YAC/D,MAAM,GAAG,GAAG,IAAA,qBAAW,EAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC9C,IAAA,mBAAS,EAAC,YAAY,EAAE,GAAG,CAAC,CAAC;YAC/B,CAAC;YACD,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1C,OAAO,QAAQ,EAAE,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAChE,CAAC,EACD,SAAS,CACV,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,CAAC,MAAM,QAAQ,CAAC,CAAC;QACjD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,sEAAsE;IACtE,KAAK,CAAC,KAAK;QACT,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,MAAM,CACJ,MAAM,WAAW,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAC1C,EAAE,EAAE,CAAC;IACR,CAAC;CACF;AAhLD,wDAgLC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RoborockHomeData } from "./web_api";
|
|
2
|
+
export interface RoborockRoom {
|
|
3
|
+
/** The segment ID on the map (what `cleanRooms` takes) */
|
|
4
|
+
segmentId: number;
|
|
5
|
+
/** The room ID in the account */
|
|
6
|
+
roomId: string;
|
|
7
|
+
/** The name given in the Roborock app (`undefined` if unknown) */
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Names the rooms of the map. `get_room_mapping` maps segments to the account's room IDs, and the home data names them.
|
|
12
|
+
*
|
|
13
|
+
* @param mapping The response of `get_room_mapping` (`[[segmentId, roomId, …], …]`)
|
|
14
|
+
* @param rooms The rooms of the home data
|
|
15
|
+
* @returns The rooms of the map with their names
|
|
16
|
+
*/
|
|
17
|
+
export declare function roomNames(mapping: unknown, rooms: RoborockHomeData["rooms"]): RoborockRoom[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.roomNames = roomNames;
|
|
4
|
+
/**
|
|
5
|
+
* Names the rooms of the map. `get_room_mapping` maps segments to the account's room IDs, and the home data names them.
|
|
6
|
+
*
|
|
7
|
+
* @param mapping The response of `get_room_mapping` (`[[segmentId, roomId, …], …]`)
|
|
8
|
+
* @param rooms The rooms of the home data
|
|
9
|
+
* @returns The rooms of the map with their names
|
|
10
|
+
*/
|
|
11
|
+
function roomNames(mapping, rooms) {
|
|
12
|
+
const names = new Map(rooms.map((room) => [String(room.id), room.name]));
|
|
13
|
+
if (!Array.isArray(mapping))
|
|
14
|
+
return [];
|
|
15
|
+
return mapping
|
|
16
|
+
.filter((entry) => Array.isArray(entry))
|
|
17
|
+
.map(([segmentId, roomId]) => ({
|
|
18
|
+
segmentId: Number(segmentId),
|
|
19
|
+
roomId: String(roomId),
|
|
20
|
+
name: names.get(String(roomId)),
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=rooms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rooms.js","sourceRoot":"","sources":["../../../src/lib/roborock/rooms.ts"],"names":[],"mappings":";;AAkBA,8BAaC;AApBD;;;;;;GAMG;AACH,SAAgB,SAAS,CACvB,OAAgB,EAChB,KAAgC;IAEhC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,KAAK,EAAsC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAC3E,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7B,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;QACtB,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KAChC,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RoborockSession } from "./web_api";
|
|
2
|
+
/**
|
|
3
|
+
* @returns The default path of the saved Roborock session (next to the Xiaomi Cloud one)
|
|
4
|
+
*/
|
|
5
|
+
export declare function defaultRoborockSessionFile(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Saves the session, readable only by the current user (it's as sensitive as a password).
|
|
8
|
+
*
|
|
9
|
+
* @param session The session
|
|
10
|
+
* @param file The file (defaults to {@link defaultRoborockSessionFile})
|
|
11
|
+
*/
|
|
12
|
+
export declare function saveRoborockSession(session: RoborockSession, file?: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* @param file The file (defaults to {@link defaultRoborockSessionFile})
|
|
15
|
+
* @returns The saved session, or `undefined` if there's none
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadRoborockSession(file?: string): Promise<RoborockSession | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* @param file The file (defaults to {@link defaultRoborockSessionFile})
|
|
20
|
+
*/
|
|
21
|
+
export declare function deleteRoborockSession(file?: string): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
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.defaultRoborockSessionFile = defaultRoborockSessionFile;
|
|
7
|
+
exports.saveRoborockSession = saveRoborockSession;
|
|
8
|
+
exports.loadRoborockSession = loadRoborockSession;
|
|
9
|
+
exports.deleteRoborockSession = deleteRoborockSession;
|
|
10
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const session_store_1 = require("../cloud/session_store");
|
|
13
|
+
/**
|
|
14
|
+
* @returns The default path of the saved Roborock session (next to the Xiaomi Cloud one)
|
|
15
|
+
*/
|
|
16
|
+
function defaultRoborockSessionFile() {
|
|
17
|
+
return node_path_1.default.join((0, session_store_1.defaultConfigDir)(), "roborock-session.json");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Saves the session, readable only by the current user (it's as sensitive as a password).
|
|
21
|
+
*
|
|
22
|
+
* @param session The session
|
|
23
|
+
* @param file The file (defaults to {@link defaultRoborockSessionFile})
|
|
24
|
+
*/
|
|
25
|
+
async function saveRoborockSession(session, file = defaultRoborockSessionFile()) {
|
|
26
|
+
await promises_1.default.mkdir(node_path_1.default.dirname(file), { recursive: true, mode: 0o700 });
|
|
27
|
+
await promises_1.default.writeFile(file, JSON.stringify(session, null, 2), { mode: 0o600 });
|
|
28
|
+
// writeFile's mode only applies to new files
|
|
29
|
+
await promises_1.default.chmod(file, 0o600);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param file The file (defaults to {@link defaultRoborockSessionFile})
|
|
33
|
+
* @returns The saved session, or `undefined` if there's none
|
|
34
|
+
*/
|
|
35
|
+
async function loadRoborockSession(file = defaultRoborockSessionFile()) {
|
|
36
|
+
try {
|
|
37
|
+
const session = JSON.parse(await promises_1.default.readFile(file, "utf8"));
|
|
38
|
+
if (session?.userData?.token && session?.userData?.rriot)
|
|
39
|
+
return session;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// No session saved (or unreadable)
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param file The file (defaults to {@link defaultRoborockSessionFile})
|
|
48
|
+
*/
|
|
49
|
+
async function deleteRoborockSession(file = defaultRoborockSessionFile()) {
|
|
50
|
+
await promises_1.default.rm(file, { force: true });
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=session_store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session_store.js","sourceRoot":"","sources":["../../../src/lib/roborock/session_store.ts"],"names":[],"mappings":";;;;;AAUA,gEAEC;AAQD,kDAQC;AAMD,kDAUC;AAKD,sDAIC;AArDD,gEAAkC;AAClC,0DAA6B;AAE7B,0DAA0D;AAI1D;;GAEG;AACH,SAAgB,0BAA0B;IACxC,OAAO,mBAAI,CAAC,IAAI,CAAC,IAAA,gCAAgB,GAAE,EAAE,uBAAuB,CAAC,CAAC;AAChE,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,mBAAmB,CACvC,OAAwB,EACxB,IAAI,GAAG,0BAA0B,EAAE;IAEnC,MAAM,kBAAE,CAAC,KAAK,CAAC,mBAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACrE,MAAM,kBAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,6CAA6C;IAC7C,MAAM,kBAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,mBAAmB,CACvC,IAAI,GAAG,0BAA0B,EAAE;IAEnC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC5D,IAAI,OAAO,EAAE,QAAQ,EAAE,KAAK,IAAI,OAAO,EAAE,QAAQ,EAAE,KAAK;YAAE,OAAO,OAAO,CAAC;IAC3E,CAAC;IAAC,MAAM,CAAC;QACP,mCAAmC;IACrC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CACzC,IAAI,GAAG,0BAA0B,EAAE;IAEnC,MAAM,kBAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { FetchLike } from "../cloud/http";
|
|
2
|
+
import { type RoborockRriot } from "./hawk";
|
|
3
|
+
/** The regional servers that know where an account lives (`getUrlByEmail`) */
|
|
4
|
+
export declare const ROBOROCK_BASE_URLS: string[];
|
|
5
|
+
/** The user data returned by the login */
|
|
6
|
+
export interface RoborockUserData {
|
|
7
|
+
/** Authorizes the requests to the regional server */
|
|
8
|
+
token: string;
|
|
9
|
+
rruid?: string;
|
|
10
|
+
rriot: RoborockRriot;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** What's needed to use the account without logging in again. As sensitive as a password: keep it private. */
|
|
14
|
+
export interface RoborockSession {
|
|
15
|
+
email: string;
|
|
16
|
+
/** The regional server of the account (e.g. `https://euiot.roborock.com`) */
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
/** Random ID of this client, sent (hashed) with every request */
|
|
19
|
+
clientId: string;
|
|
20
|
+
userData: RoborockUserData;
|
|
21
|
+
}
|
|
22
|
+
export interface RoborockProduct {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
/** The same model IDs as Mi Home, e.g. `roborock.vacuum.a15` */
|
|
26
|
+
model: string;
|
|
27
|
+
category?: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface RoborockHomeDevice {
|
|
31
|
+
duid: string;
|
|
32
|
+
name: string;
|
|
33
|
+
/** Encrypts the local and MQTT messages of this robot */
|
|
34
|
+
localKey: string;
|
|
35
|
+
productId: string;
|
|
36
|
+
/** Protocol version: `1.0` and `L01` carry the same commands as miIO; `A01`/`B01` are different command sets */
|
|
37
|
+
pv: string;
|
|
38
|
+
fv?: string;
|
|
39
|
+
online?: boolean;
|
|
40
|
+
sn?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
export interface RoborockHomeData {
|
|
44
|
+
id: number;
|
|
45
|
+
name: string;
|
|
46
|
+
products: RoborockProduct[];
|
|
47
|
+
devices: RoborockHomeDevice[];
|
|
48
|
+
/** Robots shared with this account by other accounts */
|
|
49
|
+
receivedDevices: RoborockHomeDevice[];
|
|
50
|
+
rooms: {
|
|
51
|
+
id: number;
|
|
52
|
+
name: string;
|
|
53
|
+
}[];
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
}
|
|
56
|
+
/** A robot of the account, with its product details */
|
|
57
|
+
export interface RoborockDevice {
|
|
58
|
+
duid: string;
|
|
59
|
+
name: string;
|
|
60
|
+
model?: string;
|
|
61
|
+
productName?: string;
|
|
62
|
+
protocolVersion: string;
|
|
63
|
+
firmwareVersion?: string;
|
|
64
|
+
online?: boolean;
|
|
65
|
+
localKey: string;
|
|
66
|
+
/** Shared with this account by another account */
|
|
67
|
+
shared: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface RoborockWebApiOptions {
|
|
70
|
+
/** Injectable `fetch` (tests) */
|
|
71
|
+
fetch?: FetchLike;
|
|
72
|
+
/** Request timeout in milliseconds (default 15s) */
|
|
73
|
+
timeoutMs?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Logs in to a Roborock account with a code sent by email (the Roborock app's default login).
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* const login = await RoborockLogin.start("me@example.com");
|
|
80
|
+
* await login.requestCode();
|
|
81
|
+
* const session = await login.loginWithCode(code);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare class RoborockLogin {
|
|
85
|
+
private readonly http;
|
|
86
|
+
readonly email: string;
|
|
87
|
+
/** The regional server of the account */
|
|
88
|
+
readonly baseUrl: string;
|
|
89
|
+
readonly country: string | undefined;
|
|
90
|
+
readonly countryCode: string | undefined;
|
|
91
|
+
private readonly clientId;
|
|
92
|
+
private constructor();
|
|
93
|
+
/**
|
|
94
|
+
* Finds the regional server of the account.
|
|
95
|
+
*
|
|
96
|
+
* @param email The email of the Roborock account
|
|
97
|
+
* @param options The options
|
|
98
|
+
* @returns The login
|
|
99
|
+
*/
|
|
100
|
+
static start(email: string, options?: RoborockWebApiOptions): Promise<RoborockLogin>;
|
|
101
|
+
private headers;
|
|
102
|
+
/**
|
|
103
|
+
* Asks Roborock to email a verification code.
|
|
104
|
+
*/
|
|
105
|
+
requestCode(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* @param code The code from the email
|
|
108
|
+
* @returns The session
|
|
109
|
+
*/
|
|
110
|
+
loginWithCode(code: string): Promise<RoborockSession>;
|
|
111
|
+
private loginV4;
|
|
112
|
+
/**
|
|
113
|
+
* @param country The country of the account
|
|
114
|
+
* @returns The current version of the user agreement: the login rejects an outdated one
|
|
115
|
+
*/
|
|
116
|
+
private agreementVersion;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The account API, once logged in.
|
|
120
|
+
*/
|
|
121
|
+
export declare class RoborockWebApi {
|
|
122
|
+
readonly session: RoborockSession;
|
|
123
|
+
private readonly http;
|
|
124
|
+
constructor(session: RoborockSession, options?: RoborockWebApiOptions);
|
|
125
|
+
/**
|
|
126
|
+
* @returns The ID of the account's home
|
|
127
|
+
*/
|
|
128
|
+
getHomeId(): Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* @returns The home data: robots (with their local keys), products and rooms
|
|
131
|
+
*/
|
|
132
|
+
getHomeData(): Promise<RoborockHomeData>;
|
|
133
|
+
/**
|
|
134
|
+
* @returns The robots of the account (own and shared), with their models
|
|
135
|
+
*/
|
|
136
|
+
getDevices(): Promise<RoborockDevice[]>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @param home The home data
|
|
140
|
+
* @returns The robots of the home (own and shared), with their product details
|
|
141
|
+
*/
|
|
142
|
+
export declare function toDevices(home: RoborockHomeData): RoborockDevice[];
|