node-miio 0.3.0-beta.4 → 0.4.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 (47) hide show
  1. package/.claude/settings.json +5 -0
  2. package/.claude/skills/release/SKILL.md +62 -0
  3. package/AGENTS.md +10 -0
  4. package/LICENSE.md +28 -0
  5. package/README.md +43 -37
  6. package/dist/cli/commands/cloud/devices.js +71 -0
  7. package/dist/cli/commands/cloud/devices.js.map +1 -0
  8. package/dist/cli/commands/cloud/login.js +63 -0
  9. package/dist/cli/commands/cloud/login.js.map +1 -0
  10. package/dist/cli/commands/cloud/logout.js +14 -0
  11. package/dist/cli/commands/cloud/logout.js.map +1 -0
  12. package/dist/cli/commands/cloud.js +49 -0
  13. package/dist/cli/commands/cloud.js.map +1 -0
  14. package/dist/cli/index.js +2 -0
  15. package/dist/cli/index.js.map +1 -1
  16. package/dist/cli/prompt.js +42 -0
  17. package/dist/cli/prompt.js.map +1 -0
  18. package/dist/cli/terminal_qr.js +14 -0
  19. package/dist/cli/terminal_qr.js.map +1 -0
  20. package/dist/lib/cloud/client.js +285 -0
  21. package/dist/lib/cloud/client.js.map +1 -0
  22. package/dist/lib/cloud/crypto.js +128 -0
  23. package/dist/lib/cloud/crypto.js.map +1 -0
  24. package/dist/lib/cloud/errors.js +50 -0
  25. package/dist/lib/cloud/errors.js.map +1 -0
  26. package/dist/lib/cloud/http.js +159 -0
  27. package/dist/lib/cloud/http.js.map +1 -0
  28. package/dist/lib/cloud/index.js +22 -0
  29. package/dist/lib/cloud/index.js.map +1 -0
  30. package/dist/lib/cloud/login.js +352 -0
  31. package/dist/lib/cloud/login.js.map +1 -0
  32. package/dist/lib/cloud/session_store.js +71 -0
  33. package/dist/lib/cloud/session_store.js.map +1 -0
  34. package/dist/lib/devices/vacuums/miot-vacuum.js +49 -0
  35. package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -1
  36. package/dist/lib/devices/vacuums/vacuum.js +80 -0
  37. package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
  38. package/dist/lib/index.js +14 -1
  39. package/dist/lib/index.js.map +1 -1
  40. package/dist/lib/maps/map_watcher.js +130 -0
  41. package/dist/lib/maps/map_watcher.js.map +1 -0
  42. package/dist/lib/maps/roborock_map.js +269 -0
  43. package/dist/lib/maps/roborock_map.js.map +1 -0
  44. package/docs/cloud.md +74 -0
  45. package/docs/devices/vacuum.md +19 -1
  46. package/package.json +2 -1
  47. package/snapshots/vacuum-specs.json.gz +0 -0
package/docs/cloud.md ADDED
@@ -0,0 +1,74 @@
1
+ # Xiaomi Cloud (opt-in)
2
+
3
+ node-miio controls devices **locally**. The Xiaomi Cloud is only used when you ask for it, to:
4
+
5
+ - **get the tokens** of the devices in your Xiaomi account (no more token-extraction scripts);
6
+ - (coming next) download the **map** of a vacuum, to know which room it's cleaning.
7
+
8
+ ## Command line
9
+
10
+ ```sh
11
+ # Log in by scanning a QR code with the Mi Home app (no password needed)
12
+ npx node-miio cloud login --qr
13
+
14
+ # …or with your username and password (Xiaomi may ask for a captcha or an emailed verification code)
15
+ npx node-miio cloud login
16
+
17
+ # List your devices, with their IP, ID and token
18
+ npx node-miio cloud devices
19
+ npx node-miio cloud devices --server de --json
20
+ npx node-miio cloud devices --save # store the tokens for the other node-miio commands
21
+
22
+ # Delete the saved session
23
+ npx node-miio cloud logout
24
+ ```
25
+
26
+ Your password is never stored, and it's never sent in plain text: only its MD5 hash is sent, like the Mi Home app
27
+ does. The **session** is saved to `cloud-session.json` in node-miio's config directory, readable only by you:
28
+
29
+ - macOS: `~/Library/Application Support/node-miio`
30
+ - Linux: `$XDG_CONFIG_HOME/node-miio` (`~/.config/node-miio`)
31
+ - Windows: `%APPDATA%\node-miio`
32
+ - or `MIIO_CONFIG_DIR`
33
+
34
+ Treat that file like a password: anyone with it can access your Xiaomi account.
35
+
36
+ The servers are `cn`, `de`, `us`, `ru`, `tw`, `sg`, `in` and `i2`. Without `--server`, all of them are checked.
37
+
38
+ ## API
39
+
40
+ ```ts
41
+ import {
42
+ XiaomiCloud,
43
+ loadSession,
44
+ saveSession,
45
+ CloudSessionExpiredError,
46
+ } from "node-miio";
47
+
48
+ const cloud = await XiaomiCloud.loginWithQrCode({
49
+ onQrCode: ({ imageUrl, loginUrl }) =>
50
+ console.log(`Scan ${imageUrl} (or open ${loginUrl})`),
51
+ });
52
+ // or: await XiaomiCloud.loginWithPassword(username, password, { solveCaptcha, getVerificationCode })
53
+ await saveSession(cloud.session);
54
+
55
+ // Later: reuse the session
56
+ const session = await loadSession();
57
+ const devices = await new XiaomiCloud(session!).getDevices({ servers: ["de"] });
58
+ // [{ did, name, model, token, localip, mac, server, homeId, homeOwner }]
59
+ ```
60
+
61
+ Errors:
62
+
63
+ - `CloudAuthError`: wrong credentials, captcha or verification code.
64
+ - `CloudCaptchaRequiredError` / `CloudTwoFactorRequiredError`: Xiaomi asks for a captcha / an emailed code and no
65
+ callback was provided. They include the `captchaUrl` / `notificationUrl`.
66
+ - `CloudSessionExpiredError`: log in again.
67
+ - `CloudApiError`: any other API error (`code`).
68
+
69
+ ## Credits
70
+
71
+ The login flows and the API's request signing are ported from
72
+ [Xiaomi-cloud-tokens-extractor](https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor) and
73
+ [Xiaomi-Cloud-Map-Extractor](https://github.com/PiotrMachowski/Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor)
74
+ by Piotr Machowski (MIT).
@@ -95,6 +95,16 @@ const waterLevels = await device.waterBoxModes(); // [] if not supported
95
95
  if (waterLevels.length) await device.setWaterBoxMode(waterLevels[1].value);
96
96
  ```
97
97
 
98
+ ### Cleaning type (MIoT vacuums)
99
+
100
+ MIoT vacuums that let you choose between vacuuming, mopping or both expose the options from their spec:
101
+
102
+ ```javascript
103
+ const types = await device.cleaningTypes();
104
+ // [{ value: 1, name: "Sweep" }, { value: 2, name: "Mop" }, { value: 3, name: "Sweep Mop" }, { value: 4, name: "Sweep Before Mopping" }]
105
+ await device.setCleaningType(types[3].value);
106
+ ```
107
+
98
108
  ### Roborock-only features
99
109
 
100
110
  ```javascript
@@ -117,8 +127,16 @@ await device.setMopRoute(MOP_ROUTES.deep);
117
127
  const maps = await device.getMaps(); // [{ id: 0, name: "Ground floor" }, ...]
118
128
  await device.loadMap(maps[1].id);
119
129
 
120
- // Docks with mop washing
130
+ // Docks with mop washing / drying
121
131
  await device.startMopWash();
132
+ await device.startMopDrying();
133
+ await device.stopMopDrying();
134
+
135
+ // Water tank and dock status (only on the models that report them, `undefined` otherwise).
136
+ // They're also part of `device.state()` and the `stateChanged` events.
137
+ device.property("waterBoxAttached"); // true when the water tank is mounted
138
+ device.property("waterShortage"); // true when the (dock's) clean water tank is empty
139
+ device.property("mopDrying"); // true while the dock dries the mop
122
140
 
123
141
  // Consumables and volume
124
142
  await device.resetConsumable("filter_work_time");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-miio",
3
- "version": "0.3.0-beta.4",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "description": "Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more",
6
6
  "author": "https://github.com/afharo",
@@ -49,6 +49,7 @@
49
49
  "deep-equal": "^2.2.3",
50
50
  "node-persist": "^4.0.4",
51
51
  "tinkerhub-discovery": "^0.6.0",
52
+ "uqr": "^0.1.3",
52
53
  "yargs": "^18.2.0"
53
54
  },
54
55
  "devDependencies": {
Binary file