node-miio 0.5.0 → 0.6.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/dist/cli/commands/cloud/map.d.ts +10 -0
- package/dist/cli/commands/cloud/map.js +131 -0
- package/dist/cli/commands/cloud/map.js.map +1 -0
- package/dist/cli/commands/cloud.d.ts +1 -1
- package/dist/cli/commands/cloud.js +3 -1
- package/dist/cli/commands/cloud.js.map +1 -1
- package/docs/cloud.md +5 -1
- package/package.json +1 -1
- package/snapshots/vacuum-specs.json.gz +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CommandBuilder } from "yargs";
|
|
2
|
+
export declare const command = "map <device>";
|
|
3
|
+
export declare const description = "Download the map of a Roborock vacuum: rooms, robot position and current room";
|
|
4
|
+
export declare const builder: CommandBuilder;
|
|
5
|
+
export declare const handler: (argv: {
|
|
6
|
+
device: string;
|
|
7
|
+
ip?: string;
|
|
8
|
+
out?: string;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,131 @@
|
|
|
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.handler = exports.builder = exports.description = exports.command = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const index_1 = require("../../../lib/cloud/index");
|
|
9
|
+
const connect_to_device_1 = require("../../../lib/connect_to_device");
|
|
10
|
+
const vacuum_1 = require("../../../lib/devices/vacuums/vacuum");
|
|
11
|
+
const roborock_map_1 = require("../../../lib/maps/roborock_map");
|
|
12
|
+
const log_1 = require("../../log");
|
|
13
|
+
exports.command = "map <device>";
|
|
14
|
+
exports.description = "Download the map of a Roborock vacuum: rooms, robot position and current room";
|
|
15
|
+
exports.builder = {
|
|
16
|
+
ip: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "The IP of the vacuum (defaults to the one reported by the Xiaomi Cloud)",
|
|
19
|
+
},
|
|
20
|
+
out: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Save the raw map file (gzipped), e.g. to attach it to a bug report",
|
|
23
|
+
},
|
|
24
|
+
json: { type: "boolean", description: "Print the result as JSON" },
|
|
25
|
+
};
|
|
26
|
+
const IPV4 = /^\d{1,3}(\.\d{1,3}){3}$/;
|
|
27
|
+
const handler = async (argv) => {
|
|
28
|
+
const session = await (0, index_1.loadSession)();
|
|
29
|
+
if (!session) {
|
|
30
|
+
log_1.log.error("Not logged in. Run: node-miio cloud login");
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let vacuum;
|
|
35
|
+
try {
|
|
36
|
+
const cloud = new index_1.XiaomiCloud(session);
|
|
37
|
+
const target = String(argv.device);
|
|
38
|
+
const device = await cloud.findDevice(IPV4.test(target) ? { ip: target } : { did: target });
|
|
39
|
+
if (!device) {
|
|
40
|
+
log_1.log.error(`${target} isn't in your Xiaomi account (use the device ID or IP from: node-miio cloud devices)`);
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!/^(roborock|rockrobo)\./.test(device.model)) {
|
|
45
|
+
log_1.log.error(`Only Roborock maps are supported for now (${device.model}). Please open an issue to request your model.`);
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const address = argv.ip ?? (IPV4.test(target) ? target : device.localip);
|
|
50
|
+
if (!address) {
|
|
51
|
+
log_1.log.error("The IP of the vacuum is unknown: use --ip");
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// The map name comes from the vacuum itself (local network), the file from the cloud
|
|
56
|
+
const connected = await (0, connect_to_device_1.connectToDevice)({
|
|
57
|
+
address,
|
|
58
|
+
token: device.token,
|
|
59
|
+
});
|
|
60
|
+
if (!(connected instanceof vacuum_1.Vacuum)) {
|
|
61
|
+
log_1.log.error(`Unexpected device type for ${device.model}`);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
vacuum = connected;
|
|
66
|
+
const name = await vacuum.getMapName();
|
|
67
|
+
const url = await cloud.getMapFileUrl(device.server, name);
|
|
68
|
+
const file = await cloud.download(url);
|
|
69
|
+
if (argv.out) {
|
|
70
|
+
await promises_1.default.writeFile(argv.out, file);
|
|
71
|
+
}
|
|
72
|
+
const map = (0, roborock_map_1.parseRoborockMap)(file);
|
|
73
|
+
const roomNames = new Map();
|
|
74
|
+
try {
|
|
75
|
+
for (const [id, roomName] of await vacuum.getRoomMap()) {
|
|
76
|
+
roomNames.set(Number(id), String(roomName));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Older firmware: no room names
|
|
81
|
+
}
|
|
82
|
+
const summary = {
|
|
83
|
+
model: device.model,
|
|
84
|
+
mapVersion: `${map.majorVersion}.${map.minorVersion}`,
|
|
85
|
+
rooms: map.rooms.map((room) => ({
|
|
86
|
+
...room,
|
|
87
|
+
name: roomNames.get(room.id),
|
|
88
|
+
})),
|
|
89
|
+
robot: map.robot,
|
|
90
|
+
charger: map.charger,
|
|
91
|
+
currentRoom: map.currentRoom,
|
|
92
|
+
pathPoints: map.path.length,
|
|
93
|
+
};
|
|
94
|
+
if (argv.json) {
|
|
95
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
log_1.log.info(`Map of ${device.name} (${device.model})`);
|
|
99
|
+
log_1.log.plain(` Rooms: ${map.rooms.length}`);
|
|
100
|
+
for (const room of summary.rooms) {
|
|
101
|
+
log_1.log.plain(` ${room.id}${room.name ? ` (${room.name})` : ""}`);
|
|
102
|
+
}
|
|
103
|
+
log_1.log.plain(` Robot: ${map.robot ? `${map.robot.x}, ${map.robot.y}` : "-"}`);
|
|
104
|
+
log_1.log.plain(` Charger: ${map.charger ? `${map.charger.x}, ${map.charger.y}` : "-"}`);
|
|
105
|
+
const current = map.currentRoom;
|
|
106
|
+
log_1.log.plain(` Current room: ${current === undefined
|
|
107
|
+
? "none (e.g. docked, or between rooms)"
|
|
108
|
+
: `${current}${roomNames.get(current) ? ` (${roomNames.get(current)})` : ""}`}`);
|
|
109
|
+
}
|
|
110
|
+
if (argv.out)
|
|
111
|
+
log_1.log.info(`Map file saved to ${argv.out}`);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
if (err instanceof index_1.CloudSessionExpiredError) {
|
|
115
|
+
log_1.log.error("The session expired. Run: node-miio cloud login");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
log_1.log.error(err instanceof index_1.CloudError || err instanceof Error
|
|
119
|
+
? err.message
|
|
120
|
+
: String(err));
|
|
121
|
+
}
|
|
122
|
+
process.exitCode = 1;
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
await vacuum?.destroy();
|
|
126
|
+
// The miIO network socket keeps the process alive
|
|
127
|
+
setTimeout(() => process.exit(), 100).unref(); // eslint-disable-line n/no-process-exit
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.handler = handler;
|
|
131
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../../src/cli/commands/cloud/map.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkC;AAIlC,oDAKkC;AAClC,sEAAiE;AACjE,gEAA6D;AAC7D,iEAAkE;AAClE,mCAAgC;AAEnB,QAAA,OAAO,GAAG,cAAc,CAAC;AACzB,QAAA,WAAW,GACtB,+EAA+E,CAAC;AACrE,QAAA,OAAO,GAAmB;IACrC,EAAE,EAAE;QACF,IAAI,EAAE,QAAQ;QACd,WAAW,E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;IACvB,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,EAAE,OAAO,EAAE,CAAC;QACxB,kDAAkD;QAClD,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,wCAAwC;IACzF,CAAC;AACH,CAAC,CAAC;AAzHW,QAAA,OAAO,WAyHlB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommandBuilder } from "yargs";
|
|
2
2
|
export declare const command = "cloud <command>";
|
|
3
|
-
export declare const description = "Use the Xiaomi Cloud (opt-in): log in
|
|
3
|
+
export declare const description = "Use the Xiaomi Cloud (opt-in): log in, list your devices with their tokens, download maps";
|
|
4
4
|
export declare const builder: CommandBuilder;
|
|
5
5
|
export declare const handler: () => void;
|
|
@@ -37,11 +37,13 @@ exports.handler = exports.builder = exports.description = exports.command = void
|
|
|
37
37
|
const devices = __importStar(require("./cloud/devices"));
|
|
38
38
|
const login = __importStar(require("./cloud/login"));
|
|
39
39
|
const logout = __importStar(require("./cloud/logout"));
|
|
40
|
+
const map = __importStar(require("./cloud/map"));
|
|
40
41
|
exports.command = "cloud <command>";
|
|
41
|
-
exports.description = "Use the Xiaomi Cloud (opt-in): log in
|
|
42
|
+
exports.description = "Use the Xiaomi Cloud (opt-in): log in, list your devices with their tokens, download maps";
|
|
42
43
|
const builder = (yargs) => yargs
|
|
43
44
|
.command(login)
|
|
44
45
|
.command(devices)
|
|
46
|
+
.command(map)
|
|
45
47
|
.command(logout);
|
|
46
48
|
exports.builder = builder;
|
|
47
49
|
const handler = () => { };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../../src/cli/commands/cloud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yDAA2C;AAC3C,qDAAuC;AACvC,uDAAyC;
|
|
1
|
+
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../../src/cli/commands/cloud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yDAA2C;AAC3C,qDAAuC;AACvC,uDAAyC;AACzC,iDAAmC;AAEtB,QAAA,OAAO,GAAG,iBAAiB,CAAC;AAC5B,QAAA,WAAW,GACtB,2FAA2F,CAAC;AACvF,MAAM,OAAO,GAAmB,CAAC,KAAW,EAAE,EAAE,CACrD,KAAK;KACF,OAAO,CAAC,KAAiC,CAAC;KAC1C,OAAO,CAAC,OAAmC,CAAC;KAC5C,OAAO,CAAC,GAA+B,CAAC;KACxC,OAAO,CAAC,MAAkC,CAAC,CAAC;AALpC,QAAA,OAAO,WAK6B;AAC1C,MAAM,OAAO,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAAnB,QAAA,OAAO,WAAY"}
|
package/docs/cloud.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
node-miio controls devices **locally**. The Xiaomi Cloud is only used when you ask for it, to:
|
|
4
4
|
|
|
5
5
|
- **get the tokens** of the devices in your Xiaomi account (no more token-extraction scripts);
|
|
6
|
-
-
|
|
6
|
+
- download the **map** of a Roborock vacuum, to know which room it's cleaning (see `MapWatcher`).
|
|
7
7
|
|
|
8
8
|
## Command line
|
|
9
9
|
|
|
@@ -19,6 +19,10 @@ npx node-miio cloud devices
|
|
|
19
19
|
npx node-miio cloud devices --server de --json
|
|
20
20
|
npx node-miio cloud devices --save # store the tokens for the other node-miio commands
|
|
21
21
|
|
|
22
|
+
# Download a Roborock vacuum's map: rooms, robot position and the room it's in
|
|
23
|
+
npx node-miio cloud map <device ID or IP>
|
|
24
|
+
npx node-miio cloud map 192.168.1.20 --out map.bin.gz # also save the raw map (to attach it to a bug report)
|
|
25
|
+
|
|
22
26
|
# Delete the saved session
|
|
23
27
|
npx node-miio cloud logout
|
|
24
28
|
```
|
package/package.json
CHANGED
|
Binary file
|