node-miio 0.3.0 → 0.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.
Files changed (174) hide show
  1. package/.claude/settings.json +5 -0
  2. package/.claude/skills/release/SKILL.md +73 -0
  3. package/AGENTS.md +25 -2
  4. package/CONTRIBUTING.md +41 -87
  5. package/LICENSE.md +28 -0
  6. package/README.md +86 -44
  7. package/dist/cli/commands/cloud/devices.d.ts +10 -0
  8. package/dist/cli/commands/cloud/devices.js +71 -0
  9. package/dist/cli/commands/cloud/devices.js.map +1 -0
  10. package/dist/cli/commands/cloud/login.d.ts +8 -0
  11. package/dist/cli/commands/cloud/login.js +63 -0
  12. package/dist/cli/commands/cloud/login.js.map +1 -0
  13. package/dist/cli/commands/cloud/logout.d.ts +4 -0
  14. package/dist/cli/commands/cloud/logout.js +14 -0
  15. package/dist/cli/commands/cloud/logout.js.map +1 -0
  16. package/dist/cli/commands/cloud.d.ts +5 -0
  17. package/dist/cli/commands/cloud.js +49 -0
  18. package/dist/cli/commands/cloud.js.map +1 -0
  19. package/dist/cli/commands/configure.d.ts +18 -0
  20. package/dist/cli/commands/control.d.ts +4 -0
  21. package/dist/cli/commands/discover.d.ts +9 -0
  22. package/dist/cli/commands/inspect.d.ts +4 -0
  23. package/dist/cli/commands/miot-spec.d.ts +10 -0
  24. package/dist/cli/commands/protocol/call.d.ts +9 -0
  25. package/dist/cli/commands/protocol/json-dump.d.ts +8 -0
  26. package/dist/cli/commands/protocol/packet.d.ts +8 -0
  27. package/dist/cli/commands/protocol.d.ts +5 -0
  28. package/dist/cli/commands/tokens/update.d.ts +9 -0
  29. package/dist/cli/commands/tokens.d.ts +5 -0
  30. package/dist/cli/device-finder.d.ts +3 -0
  31. package/dist/cli/index.d.ts +2 -0
  32. package/dist/cli/index.js +2 -0
  33. package/dist/cli/index.js.map +1 -1
  34. package/dist/cli/log.d.ts +9 -0
  35. package/dist/cli/prompt.d.ts +11 -0
  36. package/dist/cli/prompt.js +42 -0
  37. package/dist/cli/prompt.js.map +1 -0
  38. package/dist/cli/terminal_qr.d.ts +7 -0
  39. package/dist/cli/terminal_qr.js +14 -0
  40. package/dist/cli/terminal_qr.js.map +1 -0
  41. package/dist/lib/check_result.d.ts +6 -0
  42. package/dist/lib/cloud/client.d.ts +142 -0
  43. package/dist/lib/cloud/client.js +282 -0
  44. package/dist/lib/cloud/client.js.map +1 -0
  45. package/dist/lib/cloud/crypto.d.ts +56 -0
  46. package/dist/lib/cloud/crypto.js +128 -0
  47. package/dist/lib/cloud/crypto.js.map +1 -0
  48. package/dist/lib/cloud/errors.d.ts +26 -0
  49. package/dist/lib/cloud/errors.js +50 -0
  50. package/dist/lib/cloud/errors.js.map +1 -0
  51. package/dist/lib/cloud/http.d.ts +55 -0
  52. package/dist/lib/cloud/http.js +159 -0
  53. package/dist/lib/cloud/http.js.map +1 -0
  54. package/dist/lib/cloud/index.d.ts +5 -0
  55. package/dist/lib/cloud/index.js +22 -0
  56. package/dist/lib/cloud/index.js.map +1 -0
  57. package/dist/lib/cloud/login.d.ts +57 -0
  58. package/dist/lib/cloud/login.js +352 -0
  59. package/dist/lib/cloud/login.js.map +1 -0
  60. package/dist/lib/cloud/session_store.d.ts +27 -0
  61. package/dist/lib/cloud/session_store.js +71 -0
  62. package/dist/lib/cloud/session_store.js.map +1 -0
  63. package/dist/lib/connect_to_device.d.ts +10 -0
  64. package/dist/lib/device.d.ts +151 -0
  65. package/dist/lib/device.js +53 -19
  66. package/dist/lib/device.js.map +1 -1
  67. package/dist/lib/device_info.d.ts +66 -0
  68. package/dist/lib/device_info.js +23 -10
  69. package/dist/lib/device_info.js.map +1 -1
  70. package/dist/lib/devices/air-monitor.d.ts +8 -0
  71. package/dist/lib/devices/air-purifier.d.ts +40 -0
  72. package/dist/lib/devices/capabilities/battery-level.d.ts +22 -0
  73. package/dist/lib/devices/capabilities/buzzer.d.ts +33 -0
  74. package/dist/lib/devices/capabilities/changeable-led-brightness.d.ts +35 -0
  75. package/dist/lib/devices/capabilities/colorable.d.ts +21 -0
  76. package/dist/lib/devices/capabilities/dimmable.d.ts +21 -0
  77. package/dist/lib/devices/capabilities/mode.d.ts +21 -0
  78. package/dist/lib/devices/capabilities/power.d.ts +21 -0
  79. package/dist/lib/devices/capabilities/sensor.d.ts +15 -0
  80. package/dist/lib/devices/capabilities/switchable-led.d.ts +35 -0
  81. package/dist/lib/devices/chuangmi.plug.v1.d.ts +31 -0
  82. package/dist/lib/devices/eyecare-lamp2.d.ts +91 -0
  83. package/dist/lib/devices/gateway/86sw1.d.ts +7 -0
  84. package/dist/lib/devices/gateway/86sw2.d.ts +7 -0
  85. package/dist/lib/devices/gateway/ctrl_ln1.d.ts +8 -0
  86. package/dist/lib/devices/gateway/ctrl_ln2.d.ts +8 -0
  87. package/dist/lib/devices/gateway/ctrl_neutral1.d.ts +8 -0
  88. package/dist/lib/devices/gateway/ctrl_neutral2.d.ts +8 -0
  89. package/dist/lib/devices/gateway/cube.d.ts +6 -0
  90. package/dist/lib/devices/gateway/developer-api.d.ts +15 -0
  91. package/dist/lib/devices/gateway/light-channel.d.ts +10 -0
  92. package/dist/lib/devices/gateway/light-mixin.d.ts +2 -0
  93. package/dist/lib/devices/gateway/magnet.d.ts +6 -0
  94. package/dist/lib/devices/gateway/magnet2.d.ts +5 -0
  95. package/dist/lib/devices/gateway/motion.d.ts +6 -0
  96. package/dist/lib/devices/gateway/motion2.d.ts +6 -0
  97. package/dist/lib/devices/gateway/plug.d.ts +6 -0
  98. package/dist/lib/devices/gateway/sensor_ht.d.ts +5 -0
  99. package/dist/lib/devices/gateway/subdevice.d.ts +70 -0
  100. package/dist/lib/devices/gateway/subdevices.d.ts +49 -0
  101. package/dist/lib/devices/gateway/switch.d.ts +6 -0
  102. package/dist/lib/devices/gateway/switch2.d.ts +6 -0
  103. package/dist/lib/devices/gateway/voltage.d.ts +23 -0
  104. package/dist/lib/devices/gateway/weather.d.ts +5 -0
  105. package/dist/lib/devices/gateway.d.ts +98 -0
  106. package/dist/lib/devices/humidifier.d.ts +20 -0
  107. package/dist/lib/devices/philips-light-bulb.d.ts +8 -0
  108. package/dist/lib/devices/power-plug.d.ts +30 -0
  109. package/dist/lib/devices/power-strip.d.ts +7 -0
  110. package/dist/lib/devices/vacuums/dreamevacuum.d.ts +81 -0
  111. package/dist/lib/devices/vacuums/dreamevacuum.js +10 -2
  112. package/dist/lib/devices/vacuums/dreamevacuum.js.map +1 -1
  113. package/dist/lib/devices/vacuums/mijiavacuum.d.ts +4 -0
  114. package/dist/lib/devices/vacuums/miot-vacuum.d.ts +130 -0
  115. package/dist/lib/devices/vacuums/miot-vacuum.js +2 -0
  116. package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -1
  117. package/dist/lib/devices/vacuums/vacuum.d.ts +276 -0
  118. package/dist/lib/devices/vacuums/vacuum.js +82 -0
  119. package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
  120. package/dist/lib/devices/vacuums/vacuum_device.d.ts +17 -0
  121. package/dist/lib/devices/vacuums/vacuum_device.js +14 -0
  122. package/dist/lib/devices/vacuums/vacuum_device.js.map +1 -0
  123. package/dist/lib/devices/vacuums/vacuum_errors.d.ts +10 -0
  124. package/dist/lib/devices/vacuums/vacuum_errors.js +25 -0
  125. package/dist/lib/devices/vacuums/vacuum_errors.js.map +1 -0
  126. package/dist/lib/devices/vacuums/vacuum_modes.d.ts +51 -0
  127. package/dist/lib/devices/vacuums/viomivacuum.d.ts +76 -0
  128. package/dist/lib/devices/vacuums/viomivacuum.js +2 -0
  129. package/dist/lib/devices/vacuums/viomivacuum.js.map +1 -1
  130. package/dist/lib/devices/yeelight.color.d.ts +3 -0
  131. package/dist/lib/devices/yeelight.d.ts +159 -0
  132. package/dist/lib/devices/yeelight.mono.d.ts +3 -0
  133. package/dist/lib/discovery.d.ts +53 -0
  134. package/dist/lib/events.d.ts +18 -0
  135. package/dist/lib/events.js +3 -0
  136. package/dist/lib/events.js.map +1 -0
  137. package/dist/lib/index.d.ts +60 -0
  138. package/dist/lib/index.js +18 -1
  139. package/dist/lib/index.js.map +1 -1
  140. package/dist/lib/info_from_hostname.d.ts +13 -0
  141. package/dist/lib/logger.d.ts +43 -0
  142. package/dist/lib/logger.js +62 -0
  143. package/dist/lib/logger.js.map +1 -0
  144. package/dist/lib/management.d.ts +53 -0
  145. package/dist/lib/maps/map_watcher.d.ts +71 -0
  146. package/dist/lib/maps/map_watcher.js +127 -0
  147. package/dist/lib/maps/map_watcher.js.map +1 -0
  148. package/dist/lib/maps/roborock_map.d.ts +83 -0
  149. package/dist/lib/maps/roborock_map.js +269 -0
  150. package/dist/lib/maps/roborock_map.js.map +1 -0
  151. package/dist/lib/miio_error.d.ts +12 -0
  152. package/dist/lib/miot/miot_api.d.ts +54 -0
  153. package/dist/lib/miot/miot_spec.d.ts +114 -0
  154. package/dist/lib/miot/spec_client.d.ts +125 -0
  155. package/dist/lib/miot/spec_client.js +2 -2
  156. package/dist/lib/miot/spec_client.js.map +1 -1
  157. package/dist/lib/models.d.ts +271 -0
  158. package/dist/lib/network.d.ts +58 -0
  159. package/dist/lib/network.js +5 -2
  160. package/dist/lib/network.js.map +1 -1
  161. package/dist/lib/packet.d.ts +21 -0
  162. package/dist/lib/placeholder.d.ts +7 -0
  163. package/dist/lib/protocol.d.ts +299 -0
  164. package/dist/lib/safeish_json.d.ts +7 -0
  165. package/dist/lib/tokens.d.ts +12 -0
  166. package/dist/types/abstract-things/climate/index.d.ts +431 -0
  167. package/dist/types/abstract-things/electricals/index.d.ts +5 -0
  168. package/dist/types/abstract-things/index.d.ts +206 -0
  169. package/dist/types/abstract-things/lights/index.d.ts +14 -0
  170. package/dist/types/abstract-things/values/index.d.ts +12 -0
  171. package/docs/cloud.md +74 -0
  172. package/docs/devices/vacuum.md +9 -1
  173. package/package.json +7 -3
  174. package/snapshots/vacuum-specs.json.gz +0 -0
@@ -0,0 +1,63 @@
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 node_os_1 = __importDefault(require("node:os"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const index_1 = require("../../../lib/cloud/index");
11
+ const log_1 = require("../../log");
12
+ const prompt_1 = require("../../prompt");
13
+ const terminal_qr_1 = require("../../terminal_qr");
14
+ exports.command = "login";
15
+ exports.description = "Log in to the Xiaomi Cloud (the session is saved, your password is not)";
16
+ exports.builder = {
17
+ qr: {
18
+ type: "boolean",
19
+ description: "Log in by scanning a QR code with the Mi Home app (no password)",
20
+ },
21
+ username: {
22
+ type: "string",
23
+ description: "Email, phone number or Xiaomi user ID (asked if not given)",
24
+ },
25
+ };
26
+ const handler = async (argv) => {
27
+ try {
28
+ const cloud = argv.qr
29
+ ? await index_1.XiaomiCloud.loginWithQrCode({
30
+ onQrCode: ({ imageUrl, loginUrl, timeoutMs }) => {
31
+ log_1.log.info("Scan this QR code with the Mi Home app (Profile → Scan):");
32
+ // The QR code image encodes the login URL
33
+ console.log((0, terminal_qr_1.terminalQr)(loginUrl));
34
+ log_1.log.plain("If it doesn't scan, open this image and scan it instead:");
35
+ log_1.log.plain(` ${imageUrl}`);
36
+ log_1.log.plain(`Waiting up to ${Math.round(timeoutMs / 60000)} minutes…`);
37
+ },
38
+ })
39
+ : await index_1.XiaomiCloud.loginWithPassword(argv.username ||
40
+ (await (0, prompt_1.prompt)("Username (email, phone or user ID): ")), await (0, prompt_1.prompt)("Password (not displayed): ", { hidden: true }), {
41
+ solveCaptcha: async (image) => {
42
+ const file = node_path_1.default.join(node_os_1.default.tmpdir(), `node-miio-captcha-${Date.now()}.jpg`);
43
+ await promises_1.default.writeFile(file, image);
44
+ log_1.log.warn(`Xiaomi asks to solve a captcha. Open ${file}`);
45
+ return (0, prompt_1.prompt)("Captcha (case-sensitive): ");
46
+ },
47
+ getVerificationCode: () => {
48
+ log_1.log.warn("Xiaomi sent a verification code to your email.");
49
+ return (0, prompt_1.prompt)("Verification code: ");
50
+ },
51
+ });
52
+ await (0, index_1.saveSession)(cloud.session);
53
+ log_1.log.info(`Logged in as user ${cloud.session.userId}.`);
54
+ log_1.log.plain(`Session saved to ${(0, index_1.defaultSessionFile)()} (readable only by you).`);
55
+ log_1.log.plain("Next: node-miio cloud devices");
56
+ }
57
+ catch (err) {
58
+ log_1.log.error(err instanceof index_1.CloudError ? err.message : String(err));
59
+ process.exitCode = 1;
60
+ }
61
+ };
62
+ exports.handler = handler;
63
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../../../src/cli/commands/cloud/login.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkC;AAClC,sDAAyB;AACzB,0DAA6B;AAI7B,oDAKkC;AAClC,mCAAgC;AAChC,yCAAsC;AACtC,mDAA+C;AAElC,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,WAAW,GACtB,yEAAyE,CAAC;AAC/D,QAAA,OAAO,GAAmB;IACrC,EAAE,EAAE;QACF,IAAI,EAAE,SAAS;QACf,WAAW,EACT,iEAAiE;KACpE;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,4DAA4D;KAC1E;CACF,CAAC;AAEK,MAAM,OAAO,GAAG,KAAK,EAAE,IAAyC,EAAE,EAAE;IACzE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE;YACnB,CAAC,CAAC,MAAM,mBAAW,CAAC,eAAe,CAAC;gBAChC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;oBAC9C,SAAG,CAAC,IAAI,CACN,0DAA0D,CAC3D,CAAC;oBACF,0CAA0C;oBAC1C,OAAO,CAAC,GAAG,CAAC,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC;oBAClC,SAAG,CAAC,KAAK,CACP,0DAA0D,CAC3D,CAAC;oBACF,SAAG,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;oBAC3B,SAAG,CAAC,KAAK,CACP,iBAAiB,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,WAAW,CAC1D,CAAC;gBACJ,CAAC;aACF,CAAC;YACJ,CAAC,CAAC,MAAM,mBAAW,CAAC,iBAAiB,CACjC,IAAI,CAAC,QAAQ;gBACX,CAAC,MAAM,IAAA,eAAM,EAAC,sCAAsC,CAAC,CAAC,EACxD,MAAM,IAAA,eAAM,EAAC,4BAA4B,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAC5D;gBACE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBAC5B,MAAM,IAAI,GAAG,mBAAI,CAAC,IAAI,CACpB,iBAAE,CAAC,MAAM,EAAE,EACX,qBAAqB,IAAI,CAAC,GAAG,EAAE,MAAM,CACtC,CAAC;oBACF,MAAM,kBAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;oBAChC,SAAG,CAAC,IAAI,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;oBACzD,OAAO,IAAA,eAAM,EAAC,4BAA4B,CAAC,CAAC;gBAC9C,CAAC;gBACD,mBAAmB,EAAE,GAAG,EAAE;oBACxB,SAAG,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;oBAC3D,OAAO,IAAA,eAAM,EAAC,qBAAqB,CAAC,CAAC;gBACvC,CAAC;aACF,CACF,CAAC;QACN,MAAM,IAAA,mBAAW,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,SAAG,CAAC,IAAI,CAAC,qBAAqB,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACvD,SAAG,CAAC,KAAK,CACP,oBAAoB,IAAA,0BAAkB,GAAE,0BAA0B,CACnE,CAAC;QACF,SAAG,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,SAAG,CAAC,KAAK,CAAC,GAAG,YAAY,kBAAU,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACjE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;AAjDW,QAAA,OAAO,WAiDlB"}
@@ -0,0 +1,4 @@
1
+ export declare const command = "logout";
2
+ export declare const description = "Delete the saved Xiaomi Cloud session";
3
+ export declare const builder: {};
4
+ export declare const handler: () => Promise<void>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.description = exports.command = void 0;
4
+ const index_1 = require("../../../lib/cloud/index");
5
+ const log_1 = require("../../log");
6
+ exports.command = "logout";
7
+ exports.description = "Delete the saved Xiaomi Cloud session";
8
+ exports.builder = {};
9
+ const handler = async () => {
10
+ await (0, index_1.deleteSession)();
11
+ log_1.log.info(`Deleted ${(0, index_1.defaultSessionFile)()}`);
12
+ };
13
+ exports.handler = handler;
14
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../../../src/cli/commands/cloud/logout.ts"],"names":[],"mappings":";;;AAAA,oDAA6E;AAC7E,mCAAgC;AAEnB,QAAA,OAAO,GAAG,QAAQ,CAAC;AACnB,QAAA,WAAW,GAAG,uCAAuC,CAAC;AACtD,QAAA,OAAO,GAAG,EAAE,CAAC;AAEnB,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;IAChC,MAAM,IAAA,qBAAa,GAAE,CAAC;IACtB,SAAG,CAAC,IAAI,CAAC,WAAW,IAAA,0BAAkB,GAAE,EAAE,CAAC,CAAC;AAC9C,CAAC,CAAC;AAHW,QAAA,OAAO,WAGlB"}
@@ -0,0 +1,5 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "cloud <command>";
3
+ export declare const description = "Use the Xiaomi Cloud (opt-in): log in and list your devices with their tokens";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: () => void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.handler = exports.builder = exports.description = exports.command = void 0;
37
+ const devices = __importStar(require("./cloud/devices"));
38
+ const login = __importStar(require("./cloud/login"));
39
+ const logout = __importStar(require("./cloud/logout"));
40
+ exports.command = "cloud <command>";
41
+ exports.description = "Use the Xiaomi Cloud (opt-in): log in and list your devices with their tokens";
42
+ const builder = (yargs) => yargs
43
+ .command(login)
44
+ .command(devices)
45
+ .command(logout);
46
+ exports.builder = builder;
47
+ const handler = () => { };
48
+ exports.handler = handler;
49
+ //# sourceMappingURL=cloud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../../src/cli/commands/cloud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yDAA2C;AAC3C,qDAAuC;AACvC,uDAAyC;AAE5B,QAAA,OAAO,GAAG,iBAAiB,CAAC;AAC5B,QAAA,WAAW,GACtB,+EAA+E,CAAC;AAC3E,MAAM,OAAO,GAAmB,CAAC,KAAW,EAAE,EAAE,CACrD,KAAK;KACF,OAAO,CAAC,KAAiC,CAAC;KAC1C,OAAO,CAAC,OAAmC,CAAC;KAC5C,OAAO,CAAC,MAAkC,CAAC,CAAC;AAJpC,QAAA,OAAO,WAI6B;AAC1C,MAAM,OAAO,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAAnB,QAAA,OAAO,WAAY"}
@@ -0,0 +1,18 @@
1
+ export const command: "configure <idOrIp>";
2
+ export const description: "Control a device by invoking the given method";
3
+ export namespace builder {
4
+ namespace ssid {
5
+ let required: boolean;
6
+ let description: string;
7
+ let type: string;
8
+ }
9
+ namespace passwd {
10
+ let required_1: boolean;
11
+ export { required_1 as required };
12
+ let description_1: string;
13
+ export { description_1 as description };
14
+ let type_1: string;
15
+ export { type_1 as type };
16
+ }
17
+ }
18
+ export function handler(argv: any): void;
@@ -0,0 +1,4 @@
1
+ export const command: "control <idOrIp> <method> [params..]";
2
+ export const description: "Control a device by invoking the given method";
3
+ export const builder: {};
4
+ export function handler(argv: any): void;
@@ -0,0 +1,9 @@
1
+ export const command: "discover";
2
+ export const description: "Discover devices on the local network";
3
+ export namespace builder {
4
+ namespace sync {
5
+ let type: string;
6
+ let description: string;
7
+ }
8
+ }
9
+ export function handler(argv: any): void;
@@ -0,0 +1,4 @@
1
+ export const command: "inspect <idOrIp>";
2
+ export const description: "Inspect a device";
3
+ export const builder: {};
4
+ export function handler(argv: any): void;
@@ -0,0 +1,10 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "spec <model>";
3
+ export declare const description = "Show the MIoT spec of a model (from miot-spec.org, the cache or the bundled snapshot)";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: (argv: {
6
+ model: string;
7
+ offline?: boolean;
8
+ json?: boolean;
9
+ specDir?: string;
10
+ }) => Promise<void>;
@@ -0,0 +1,9 @@
1
+ export const command: "call <idOrIp> <method> [params...]";
2
+ export const description: "Call a raw method on a device";
3
+ export namespace builder {
4
+ namespace token {
5
+ let type: string;
6
+ let description: string;
7
+ }
8
+ }
9
+ export function handler(argv: any): void;
@@ -0,0 +1,8 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "json-dump <file>";
3
+ export declare const description = "Extract packets from a Wireshark JSON dump";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: (argv: {
6
+ file: string;
7
+ token: string;
8
+ }) => void;
@@ -0,0 +1,8 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "packet <hexData>";
3
+ export declare const description = "Decode a miIO UDP packet";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: (argv: {
6
+ token: string;
7
+ hexData: string;
8
+ }) => void;
@@ -0,0 +1,5 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "protocol <command>";
3
+ export declare const description = "Inspect and test raw miIO-commands";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: () => void;
@@ -0,0 +1,9 @@
1
+ export const command: "update <idOrIp>";
2
+ export const description: "Update the token to use for the given device";
3
+ export namespace builder {
4
+ namespace token {
5
+ let required: boolean;
6
+ let description: string;
7
+ }
8
+ }
9
+ export function handler(argv: any): void;
@@ -0,0 +1,5 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "tokens <command>";
3
+ export declare const description = "Manage tokens of devices";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: () => void;
@@ -0,0 +1,3 @@
1
+ declare function _exports(options?: {}): EventEmitter<[never]>;
2
+ export = _exports;
3
+ import { EventEmitter } from "events";
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli/index.js CHANGED
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  const yargs_1 = __importDefault(require("yargs"));
41
41
  const helpers_1 = require("yargs/helpers");
42
+ const cloud = __importStar(require("./commands/cloud"));
42
43
  const configure = __importStar(require("./commands/configure"));
43
44
  const control = __importStar(require("./commands/control"));
44
45
  const discover = __importStar(require("./commands/discover"));
@@ -50,6 +51,7 @@ const tokens = __importStar(require("./commands/tokens"));
50
51
  // `commandDir` is not supported when yargs is loaded as an ES module.
51
52
  void (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
52
53
  .scriptName("node-miio")
54
+ .command(cloud)
53
55
  .command(configure)
54
56
  .command(control)
55
57
  .command(discover)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,kDAAkD;AAClD,2CAAwC;AAExC,gEAAkD;AAClD,4DAA8C;AAC9C,8DAAgD;AAChD,4DAA8C;AAC9C,8DAAgD;AAChD,2DAA6C;AAC7C,0DAA4C;AAE5C,uEAAuE;AACvE,sEAAsE;AACtE,KAAK,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B,UAAU,CAAC,WAAW,CAAC;KACvB,OAAO,CAAC,SAAqC,CAAC;KAC9C,OAAO,CAAC,OAAmC,CAAC;KAC5C,OAAO,CAAC,QAAoC,CAAC;KAC7C,OAAO,CAAC,OAAmC,CAAC;KAC5C,OAAO,CAAC,QAAoC,CAAC;KAC7C,OAAO,CAAC,IAAgC,CAAC;KACzC,OAAO,CAAC,MAAkC,CAAC;KAC3C,iBAAiB,EAAE;KACnB,aAAa,EAAE;KACf,MAAM,EAAE;KACR,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,kDAAkD;AAClD,2CAAwC;AAExC,wDAA0C;AAC1C,gEAAkD;AAClD,4DAA8C;AAC9C,8DAAgD;AAChD,4DAA8C;AAC9C,8DAAgD;AAChD,2DAA6C;AAC7C,0DAA4C;AAE5C,uEAAuE;AACvE,sEAAsE;AACtE,KAAK,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B,UAAU,CAAC,WAAW,CAAC;KACvB,OAAO,CAAC,KAAiC,CAAC;KAC1C,OAAO,CAAC,SAAqC,CAAC;KAC9C,OAAO,CAAC,OAAmC,CAAC;KAC5C,OAAO,CAAC,QAAoC,CAAC;KAC7C,OAAO,CAAC,OAAmC,CAAC;KAC5C,OAAO,CAAC,QAAoC,CAAC;KAC7C,OAAO,CAAC,IAAgC,CAAC;KACzC,OAAO,CAAC,MAAkC,CAAC;KAC3C,iBAAiB,EAAE;KACnB,aAAa,EAAE;KACf,MAAM,EAAE;KACR,KAAK,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const log: {
2
+ indent: string;
3
+ info(...args: any[]): void;
4
+ error(...args: any[]): void;
5
+ warn(...args: any[]): void;
6
+ plain(...args: any[]): void;
7
+ group(g: any): void;
8
+ device(device: any, detailed?: boolean): void;
9
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Asks a question in the terminal.
3
+ *
4
+ * @param question The question
5
+ * @param options The options
6
+ * @param options.hidden Don't echo the answer (passwords)
7
+ * @returns The answer
8
+ */
9
+ export declare function prompt(question: string, options?: {
10
+ hidden?: boolean;
11
+ }): Promise<string>;
@@ -0,0 +1,42 @@
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.prompt = prompt;
7
+ const node_readline_1 = __importDefault(require("node:readline"));
8
+ const node_stream_1 = require("node:stream");
9
+ /**
10
+ * Asks a question in the terminal.
11
+ *
12
+ * @param question The question
13
+ * @param options The options
14
+ * @param options.hidden Don't echo the answer (passwords)
15
+ * @returns The answer
16
+ */
17
+ function prompt(question, options = {}) {
18
+ let muted = false;
19
+ const output = new node_stream_1.Writable({
20
+ write(chunk, encoding, callback) {
21
+ if (!muted)
22
+ process.stdout.write(chunk, encoding);
23
+ callback();
24
+ },
25
+ });
26
+ const rl = node_readline_1.default.createInterface({
27
+ input: process.stdin,
28
+ output,
29
+ terminal: process.stdin.isTTY,
30
+ });
31
+ return new Promise((resolve) => {
32
+ rl.question(question, (answer) => {
33
+ if (options.hidden)
34
+ process.stdout.write("\n");
35
+ rl.close();
36
+ resolve(answer.trim());
37
+ });
38
+ // Mute the echo of the answer (the question is already written)
39
+ muted = !!options.hidden;
40
+ });
41
+ }
42
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/cli/prompt.ts"],"names":[],"mappings":";;;;;AAWA,wBAyBC;AApCD,kEAAqC;AACrC,6CAAuC;AAEvC;;;;;;;GAOG;AACH,SAAgB,MAAM,CACpB,QAAgB,EAChB,UAAgC,EAAE;IAElC,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,MAAM,GAAG,IAAI,sBAAQ,CAAC;QAC1B,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ;YAC7B,IAAI,CAAC,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAClD,QAAQ,EAAE,CAAC;QACb,CAAC;KACF,CAAC,CAAC;IACH,MAAM,EAAE,GAAG,uBAAQ,CAAC,eAAe,CAAC;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM;QACN,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK;KAC9B,CAAC,CAAC;IACH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YAC/B,IAAI,OAAO,CAAC,MAAM;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/C,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QACH,gEAAgE;QAChE,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Draws a QR code in the terminal (2 rows of modules per line), for dark terminal themes.
3
+ *
4
+ * @param text The text to encode
5
+ * @returns The QR code, ready to print
6
+ */
7
+ export declare function terminalQr(text: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.terminalQr = terminalQr;
4
+ const uqr_1 = require("uqr");
5
+ /**
6
+ * Draws a QR code in the terminal (2 rows of modules per line), for dark terminal themes.
7
+ *
8
+ * @param text The text to encode
9
+ * @returns The QR code, ready to print
10
+ */
11
+ function terminalQr(text) {
12
+ return (0, uqr_1.renderUnicodeCompact)(text, { border: 2 });
13
+ }
14
+ //# sourceMappingURL=terminal_qr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal_qr.js","sourceRoot":"","sources":["../../src/cli/terminal_qr.ts"],"names":[],"mappings":";;AAQA,gCAEC;AAVD,6BAA2C;AAE3C;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAA,0BAAoB,EAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Helper to validate that the response from the RVC is successful.
3
+ *
4
+ * @param r The response of the request
5
+ */
6
+ export declare function checkResult(r: unknown): void;
@@ -0,0 +1,142 @@
1
+ import { type FetchLike } from "./http";
2
+ import { type CloudSession, type PasswordLoginOptions, type QrLoginOptions } from "./login";
3
+ /** The regional servers of the Xiaomi Cloud */
4
+ export declare const CLOUD_SERVERS: readonly ["cn", "de", "us", "ru", "tw", "sg", "in", "i2"];
5
+ export type CloudServer = (typeof CLOUD_SERVERS)[number];
6
+ /** A device registered in the Xiaomi account */
7
+ export interface CloudDevice {
8
+ /** The device ID */
9
+ did: string;
10
+ name: string;
11
+ model: string;
12
+ /** The token to control the device locally */
13
+ token: string;
14
+ /** The IP of the device in the local network, as last reported */
15
+ localip?: string;
16
+ mac?: string;
17
+ isOnline?: boolean;
18
+ /** The server the device is registered in */
19
+ server: CloudServer;
20
+ homeId: string;
21
+ homeOwner: string;
22
+ }
23
+ interface Home {
24
+ homeId: string;
25
+ owner: string;
26
+ }
27
+ export interface XiaomiCloudOptions {
28
+ /** The `fetch` implementation (defaults to the global one) */
29
+ fetch?: FetchLike;
30
+ }
31
+ /**
32
+ * Client of the Xiaomi Cloud API.
33
+ *
34
+ * ```ts
35
+ * const cloud = await XiaomiCloud.loginWithQrCode({ onQrCode: ({ loginUrl }) => console.log(loginUrl) });
36
+ * const devices = await cloud.getDevices();
37
+ * ```
38
+ */
39
+ export declare class XiaomiCloud {
40
+ readonly session: CloudSession;
41
+ private readonly http;
42
+ private readonly agent;
43
+ /**
44
+ * @param session A session from a previous login (see {@link XiaomiCloud.session})
45
+ * @param options The client options
46
+ */
47
+ constructor(session: CloudSession, options?: XiaomiCloudOptions);
48
+ /**
49
+ * Logs in with a username (email, phone number or user ID) and password.
50
+ *
51
+ * @param username The username
52
+ * @param password The password
53
+ * @param options Callbacks for the captcha and the email verification
54
+ * @returns The client
55
+ */
56
+ static loginWithPassword(username: string, password: string, options?: PasswordLoginOptions): Promise<XiaomiCloud>;
57
+ /**
58
+ * Logs in by scanning a QR code with the Mi Home app.
59
+ *
60
+ * @param options The callback that shows the QR code
61
+ * @returns The client
62
+ */
63
+ static loginWithQrCode(options: QrLoginOptions): Promise<XiaomiCloud>;
64
+ /**
65
+ * @param server The regional server
66
+ * @returns The base URL of the API in that server
67
+ */
68
+ static apiUrl(server: CloudServer | string): string;
69
+ /**
70
+ * Calls the API (signed and encrypted).
71
+ *
72
+ * @param server The regional server
73
+ * @param path The API path (e.g. `/v2/homeroom/gethome`)
74
+ * @param data The request data
75
+ * @returns The `result` of the response
76
+ */
77
+ call<T = unknown>(server: CloudServer | string, path: string, data: unknown): Promise<T>;
78
+ /**
79
+ * @param server The regional server
80
+ * @returns The homes of the user and the homes shared with them
81
+ */
82
+ getHomes(server: CloudServer | string): Promise<Home[]>;
83
+ /**
84
+ * @param server The regional server
85
+ * @param home The home
86
+ * @returns The devices of the home
87
+ */
88
+ getHomeDevices(server: CloudServer, home: Home): Promise<CloudDevice[]>;
89
+ /**
90
+ * Lists the devices of the account, with their tokens.
91
+ *
92
+ * @param options The options
93
+ * @param options.servers The servers to check (all of them by default)
94
+ * @returns The devices
95
+ */
96
+ getDevices(options?: {
97
+ servers?: readonly CloudServer[];
98
+ }): Promise<CloudDevice[]>;
99
+ /**
100
+ * Finds a device of the account (e.g. to know its token or its server).
101
+ *
102
+ * @param match The device ID, token or local IP of the device (the first one given that matches)
103
+ * @param match.did The device ID
104
+ * @param match.token The device token
105
+ * @param match.ip The local IP of the device
106
+ * @param options The options of {@link XiaomiCloud.getDevices}
107
+ * @param options.servers The servers to check (all of them by default)
108
+ * @returns The device, if found
109
+ */
110
+ findDevice(match: {
111
+ did?: string | number;
112
+ token?: string;
113
+ ip?: string;
114
+ }, options?: {
115
+ servers?: readonly CloudServer[];
116
+ }): Promise<CloudDevice | undefined>;
117
+ /**
118
+ * Downloads a file (e.g. a map file from {@link XiaomiCloud.getMapFileUrl}).
119
+ *
120
+ * @param url The URL
121
+ * @returns The file contents
122
+ */
123
+ download(url: string): Promise<Buffer>;
124
+ /**
125
+ * Gets the URL of a map file (Roborock and Xiaomi vacuums). The map name comes from the device (`get_map_v1`).
126
+ *
127
+ * @param server The regional server of the device
128
+ * @param mapName The map name
129
+ * @returns The URL of the (gzipped) map file
130
+ */
131
+ getMapFileUrl(server: CloudServer | string, mapName: string): Promise<string>;
132
+ /**
133
+ * Gets the URL of a map file of the newer vacuums (Dreame, Viomi, Roidmi…).
134
+ *
135
+ * @param server The regional server of the device
136
+ * @param did The device ID
137
+ * @param mapName The map name
138
+ * @returns The URL of the map file
139
+ */
140
+ getInterimFileUrl(server: CloudServer | string, did: string, mapName: string): Promise<string>;
141
+ }
142
+ export {};