node-miio 0.4.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 (144) hide show
  1. package/.claude/skills/release/SKILL.md +11 -0
  2. package/AGENTS.md +17 -2
  3. package/CONTRIBUTING.md +41 -87
  4. package/README.md +43 -7
  5. package/dist/cli/commands/cloud/devices.d.ts +10 -0
  6. package/dist/cli/commands/cloud/login.d.ts +8 -0
  7. package/dist/cli/commands/cloud/logout.d.ts +4 -0
  8. package/dist/cli/commands/cloud.d.ts +5 -0
  9. package/dist/cli/commands/configure.d.ts +18 -0
  10. package/dist/cli/commands/control.d.ts +4 -0
  11. package/dist/cli/commands/discover.d.ts +9 -0
  12. package/dist/cli/commands/inspect.d.ts +4 -0
  13. package/dist/cli/commands/miot-spec.d.ts +10 -0
  14. package/dist/cli/commands/protocol/call.d.ts +9 -0
  15. package/dist/cli/commands/protocol/json-dump.d.ts +8 -0
  16. package/dist/cli/commands/protocol/packet.d.ts +8 -0
  17. package/dist/cli/commands/protocol.d.ts +5 -0
  18. package/dist/cli/commands/tokens/update.d.ts +9 -0
  19. package/dist/cli/commands/tokens.d.ts +5 -0
  20. package/dist/cli/device-finder.d.ts +3 -0
  21. package/dist/cli/index.d.ts +2 -0
  22. package/dist/cli/log.d.ts +9 -0
  23. package/dist/cli/prompt.d.ts +11 -0
  24. package/dist/cli/terminal_qr.d.ts +7 -0
  25. package/dist/lib/check_result.d.ts +6 -0
  26. package/dist/lib/cloud/client.d.ts +142 -0
  27. package/dist/lib/cloud/client.js +2 -5
  28. package/dist/lib/cloud/client.js.map +1 -1
  29. package/dist/lib/cloud/crypto.d.ts +56 -0
  30. package/dist/lib/cloud/errors.d.ts +26 -0
  31. package/dist/lib/cloud/http.d.ts +55 -0
  32. package/dist/lib/cloud/index.d.ts +5 -0
  33. package/dist/lib/cloud/login.d.ts +57 -0
  34. package/dist/lib/cloud/login.js +2 -2
  35. package/dist/lib/cloud/login.js.map +1 -1
  36. package/dist/lib/cloud/session_store.d.ts +27 -0
  37. package/dist/lib/connect_to_device.d.ts +10 -0
  38. package/dist/lib/device.d.ts +151 -0
  39. package/dist/lib/device.js +53 -19
  40. package/dist/lib/device.js.map +1 -1
  41. package/dist/lib/device_info.d.ts +66 -0
  42. package/dist/lib/device_info.js +23 -10
  43. package/dist/lib/device_info.js.map +1 -1
  44. package/dist/lib/devices/air-monitor.d.ts +8 -0
  45. package/dist/lib/devices/air-purifier.d.ts +40 -0
  46. package/dist/lib/devices/capabilities/battery-level.d.ts +22 -0
  47. package/dist/lib/devices/capabilities/buzzer.d.ts +33 -0
  48. package/dist/lib/devices/capabilities/changeable-led-brightness.d.ts +35 -0
  49. package/dist/lib/devices/capabilities/colorable.d.ts +21 -0
  50. package/dist/lib/devices/capabilities/dimmable.d.ts +21 -0
  51. package/dist/lib/devices/capabilities/mode.d.ts +21 -0
  52. package/dist/lib/devices/capabilities/power.d.ts +21 -0
  53. package/dist/lib/devices/capabilities/sensor.d.ts +15 -0
  54. package/dist/lib/devices/capabilities/switchable-led.d.ts +35 -0
  55. package/dist/lib/devices/chuangmi.plug.v1.d.ts +31 -0
  56. package/dist/lib/devices/eyecare-lamp2.d.ts +91 -0
  57. package/dist/lib/devices/gateway/86sw1.d.ts +7 -0
  58. package/dist/lib/devices/gateway/86sw2.d.ts +7 -0
  59. package/dist/lib/devices/gateway/ctrl_ln1.d.ts +8 -0
  60. package/dist/lib/devices/gateway/ctrl_ln2.d.ts +8 -0
  61. package/dist/lib/devices/gateway/ctrl_neutral1.d.ts +8 -0
  62. package/dist/lib/devices/gateway/ctrl_neutral2.d.ts +8 -0
  63. package/dist/lib/devices/gateway/cube.d.ts +6 -0
  64. package/dist/lib/devices/gateway/developer-api.d.ts +15 -0
  65. package/dist/lib/devices/gateway/light-channel.d.ts +10 -0
  66. package/dist/lib/devices/gateway/light-mixin.d.ts +2 -0
  67. package/dist/lib/devices/gateway/magnet.d.ts +6 -0
  68. package/dist/lib/devices/gateway/magnet2.d.ts +5 -0
  69. package/dist/lib/devices/gateway/motion.d.ts +6 -0
  70. package/dist/lib/devices/gateway/motion2.d.ts +6 -0
  71. package/dist/lib/devices/gateway/plug.d.ts +6 -0
  72. package/dist/lib/devices/gateway/sensor_ht.d.ts +5 -0
  73. package/dist/lib/devices/gateway/subdevice.d.ts +70 -0
  74. package/dist/lib/devices/gateway/subdevices.d.ts +49 -0
  75. package/dist/lib/devices/gateway/switch.d.ts +6 -0
  76. package/dist/lib/devices/gateway/switch2.d.ts +6 -0
  77. package/dist/lib/devices/gateway/voltage.d.ts +23 -0
  78. package/dist/lib/devices/gateway/weather.d.ts +5 -0
  79. package/dist/lib/devices/gateway.d.ts +98 -0
  80. package/dist/lib/devices/humidifier.d.ts +20 -0
  81. package/dist/lib/devices/philips-light-bulb.d.ts +8 -0
  82. package/dist/lib/devices/power-plug.d.ts +30 -0
  83. package/dist/lib/devices/power-strip.d.ts +7 -0
  84. package/dist/lib/devices/vacuums/dreamevacuum.d.ts +81 -0
  85. package/dist/lib/devices/vacuums/dreamevacuum.js +10 -2
  86. package/dist/lib/devices/vacuums/dreamevacuum.js.map +1 -1
  87. package/dist/lib/devices/vacuums/mijiavacuum.d.ts +4 -0
  88. package/dist/lib/devices/vacuums/miot-vacuum.d.ts +130 -0
  89. package/dist/lib/devices/vacuums/miot-vacuum.js +2 -0
  90. package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -1
  91. package/dist/lib/devices/vacuums/vacuum.d.ts +276 -0
  92. package/dist/lib/devices/vacuums/vacuum.js +2 -0
  93. package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
  94. package/dist/lib/devices/vacuums/vacuum_device.d.ts +17 -0
  95. package/dist/lib/devices/vacuums/vacuum_device.js +14 -0
  96. package/dist/lib/devices/vacuums/vacuum_device.js.map +1 -0
  97. package/dist/lib/devices/vacuums/vacuum_errors.d.ts +10 -0
  98. package/dist/lib/devices/vacuums/vacuum_errors.js +25 -0
  99. package/dist/lib/devices/vacuums/vacuum_errors.js.map +1 -0
  100. package/dist/lib/devices/vacuums/vacuum_modes.d.ts +51 -0
  101. package/dist/lib/devices/vacuums/viomivacuum.d.ts +76 -0
  102. package/dist/lib/devices/vacuums/viomivacuum.js +2 -0
  103. package/dist/lib/devices/vacuums/viomivacuum.js.map +1 -1
  104. package/dist/lib/devices/yeelight.color.d.ts +3 -0
  105. package/dist/lib/devices/yeelight.d.ts +159 -0
  106. package/dist/lib/devices/yeelight.mono.d.ts +3 -0
  107. package/dist/lib/discovery.d.ts +53 -0
  108. package/dist/lib/events.d.ts +18 -0
  109. package/dist/lib/events.js +3 -0
  110. package/dist/lib/events.js.map +1 -0
  111. package/dist/lib/index.d.ts +60 -0
  112. package/dist/lib/index.js +5 -1
  113. package/dist/lib/index.js.map +1 -1
  114. package/dist/lib/info_from_hostname.d.ts +13 -0
  115. package/dist/lib/logger.d.ts +43 -0
  116. package/dist/lib/logger.js +62 -0
  117. package/dist/lib/logger.js.map +1 -0
  118. package/dist/lib/management.d.ts +53 -0
  119. package/dist/lib/maps/map_watcher.d.ts +71 -0
  120. package/dist/lib/maps/map_watcher.js +2 -5
  121. package/dist/lib/maps/map_watcher.js.map +1 -1
  122. package/dist/lib/maps/roborock_map.d.ts +83 -0
  123. package/dist/lib/miio_error.d.ts +12 -0
  124. package/dist/lib/miot/miot_api.d.ts +54 -0
  125. package/dist/lib/miot/miot_spec.d.ts +114 -0
  126. package/dist/lib/miot/spec_client.d.ts +125 -0
  127. package/dist/lib/miot/spec_client.js +2 -2
  128. package/dist/lib/miot/spec_client.js.map +1 -1
  129. package/dist/lib/models.d.ts +271 -0
  130. package/dist/lib/network.d.ts +58 -0
  131. package/dist/lib/network.js +5 -2
  132. package/dist/lib/network.js.map +1 -1
  133. package/dist/lib/packet.d.ts +21 -0
  134. package/dist/lib/placeholder.d.ts +7 -0
  135. package/dist/lib/protocol.d.ts +299 -0
  136. package/dist/lib/safeish_json.d.ts +7 -0
  137. package/dist/lib/tokens.d.ts +12 -0
  138. package/dist/types/abstract-things/climate/index.d.ts +431 -0
  139. package/dist/types/abstract-things/electricals/index.d.ts +5 -0
  140. package/dist/types/abstract-things/index.d.ts +206 -0
  141. package/dist/types/abstract-things/lights/index.d.ts +14 -0
  142. package/dist/types/abstract-things/values/index.d.ts +12 -0
  143. package/package.json +6 -3
  144. package/snapshots/vacuum-specs.json.gz +0 -0
@@ -59,4 +59,15 @@ npm view node-miio dist-tags
59
59
  If it fails, report it: don't publish by hand without asking. Once a version is on npm, the plugins'
60
60
  Renovate (no cooldown for node-miio) opens their update PRs.
61
61
 
62
+ ## Ask the testers / tell the reporters
63
+
64
+ Once the version is on npm:
65
+
66
+ - **Beta**: comment on the beta testers issue (#18) mentioning the testers whose model or dock matches the
67
+ changes. Give them a short test list (2–3 items: "turn on X, check that Y happens") and ask for ✅ / ❌ per item, with
68
+ debug logs for ❌. Also comment on the issues the beta addresses, asking the reporters to try it. node-miio betas usually come from a plugin issue: also mention the matching testers in the plugins' issues (homebridge #1232, matterbridge #387).
69
+ - **Release**: comment on every issue it addresses: the version, how to enable/use it, and "if it doesn't work, comment
70
+ here and we'll reopen it" (reporters can't reopen issues closed by a maintainer or a PR). Keep them closed: don't
71
+ leave issues open waiting for feedback that may never come.
72
+
62
73
  Report the release and npm links to the user.
package/AGENTS.md CHANGED
@@ -20,7 +20,8 @@ Guidance for AI coding agents (and humans) working on `node-miio`.
20
20
  npm ci
21
21
  npm run lint # eslint --max-warnings=0: warnings fail CI too
22
22
  npm test # jest (babel-jest: tests are NOT type-checked, `npm run build` is)
23
- npm run build # tsc -> dist/
23
+ npm run build # tsc -> dist/ (JS + .d.ts), then scripts/copy-types.mjs ships src/types/ (abstract-things)
24
+ npm run test:types # after build: type-checks test-types/consumer.ts against the published types, like a plugin
24
25
  node dist/cli/index.js --help # smoke-test the CLI after building
25
26
  ```
26
27
 
@@ -49,11 +50,25 @@ the ESM-only yargs 18 is loaded with `require()`, which needs `require(esm)` sup
49
50
  - Commands using `refresh`/`refreshDelay` wait on timers: use fake timers and `jest.advanceTimersByTimeAsync`.
50
51
  - `src/lib/modules_load.test.ts` loads every module in isolation. It catches broken mixins and circular imports.
51
52
 
53
+ ## Published types
54
+
55
+ - The package ships declarations (`"types": "dist/lib/index.d.ts"`), so the plugins don't need hand-written ones.
56
+ `test-types/consumer.ts` uses the API the way the plugins do: when you add or change public API, use it there too.
57
+ - The class-mixin pattern (`Thing.type(...)`, `.with(...)`) can't publish private/protected members (TS4094): mark them
58
+ `/** @internal */` (removed from the declarations with `stripInternal`). Computed methods (e.g. `[util.inspect.custom]`)
59
+ can't be named either: `Device` defines that one in its constructor.
60
+ - The mixin typings live in `src/types/abstract-things/` (the package has none) and are published with the library.
61
+ `Proto<T>` (the instance type of a class or mixin) keeps the composed classes typed: `T["prototype"]` was `any`.
62
+ - `VacuumDevice` is the union of the vacuum classes: only their shared API is available without narrowing
63
+ (`instanceof Vacuum`…). Keep that shared API consistent across the classes (e.g. `cleanRooms` rejects when unsupported).
64
+
52
65
  ## Linting
53
66
 
54
67
  - JSDoc is optional. When present, it must be correct (`check-param-names`, `require-param`, `check-tag-names`).
55
68
  In `.ts` files, types come from TypeScript, so JSDoc types are not allowed (`jsdoc/no-types`). In `.js` files, `@param {type}` is required.
56
- - `console` is only allowed in `src/cli/**` and `scripts/**`. Use `debug` in the library.
69
+ - `console` is only allowed in `src/cli/**` and `scripts/**`. In the library, log with `createDebug(namespace)` from `src/lib/logger.ts`
70
+ (not the `debug` package directly): it also forwards to the logger injected by the plugins (`device({ logger })` /
71
+ `configureLogging`), and redacts tokens and passwords. Never log a token in full (use `maskToken`).
57
72
 
58
73
  ## Gotchas learned the hard way
59
74
 
package/CONTRIBUTING.md CHANGED
@@ -1,104 +1,58 @@
1
1
  # Contributing
2
2
 
3
- Contributions are welcomed in this repository, not only code changes but also
4
- opening issues, helping with questions and otherwise giving feedback.
3
+ Thank you for helping! The maintainer **doesn't own most of the supported devices**: changes are developed against
4
+ automated tests that replay what real devices answered, and they're validated by users on beta releases. So the most
5
+ valuable contributions don't need any code:
5
6
 
6
- Please note that this project has a code of conduct, please read it before
7
- jumping in and contributing to this project.
7
+ - [Become a beta tester](#become-a-beta-tester)
8
+ - [Share what your device reports](#share-what-your-device-reports)
9
+ - [Contributing code](#contributing-code)
8
10
 
9
- ## Working with the code
11
+ ## Become a beta tester
10
12
 
11
- This project doesn't have a super-strict code-style, contributions are expected
12
- to look about the same as existing code. Tabs are used for indentation except
13
- for Markdown and a few JSON-files. Install an [Editorconfig](http://editorconfig.org/)
14
- plugin in your editor to simplify white-space handling.
13
+ Most users run node-miio through a plugin. Sign up as a beta tester in the plugin you use, with your **model**,
14
+ **firmware version** and dock (if any). You'll be mentioned whenever a beta needs a device like yours:
15
15
 
16
- Before submitting a pull request, run `npm test` to run a few basic linting
17
- tests. If you have an ESLint-plugin in your editor it should run automatically
18
- while you work.
16
+ - Homebridge: [homebridge-xiaomi-roborock-vacuum#1232](https://github.com/homebridge-xiaomi-roborock-vacuum/homebridge-xiaomi-roborock-vacuum/issues/1232)
17
+ - Matterbridge: [matterbridge-xiaomi-roborock#387](https://github.com/afharo/matterbridge-xiaomi-roborock/issues/387)
19
18
 
20
- ## Issues and helping out with questions
19
+ If you use node-miio directly, comment on [#18](https://github.com/afharo/node-miio/issues/18) instead. Betas are
20
+ published with the `beta` tag: `npm install node-miio@beta`.
21
21
 
22
- This project is used both directly by developers and indirectly by end-users
23
- via other projects. When opening an issue try to include as much details about
24
- how the library is used, such as if its being used via a third-party project
25
- and the version being used.
22
+ ## Share what your device reports
26
23
 
27
- If you have know-how about the API and library please feel free to answer any
28
- questions you can. If you have the same issue as someone else, try adding a few
29
- more details if you can.
24
+ Supporting a model or a feature starts with knowing what the device answers. When opening an issue, include:
30
25
 
31
- ## Code of Conduct
26
+ - [ ] The **model** and **firmware version**: `npx node-miio@latest protocol call <ip> miIO.info --token <token>` (the
27
+ `model` and `fw_ver` fields).
28
+ - [ ] What you'd like to do, and **how you do it in the Mi Home app**.
29
+ - [ ] Raw captures:
30
+ - Roborock (`roborock.vacuum.*`, `rockrobo.vacuum.*`):
31
+ `npx node-miio@latest protocol call <ip> get_status --token <token>`. Ideally twice: before and after doing the
32
+ action in the app, so we can see which field changes.
33
+ - Any other brand (MIoT devices): `npx node-miio@latest spec <model>`.
34
+ - [ ] Whether you can test a beta.
32
35
 
33
- ### Our Pledge
36
+ Replies are turned into test fixtures (`src/lib/__fixtures__/`), so the behaviour stays covered without the device.
34
37
 
35
- In the interest of fostering an open and welcoming environment, we as
36
- contributors and maintainers pledge to making participation in our project and
37
- our community a harassment-free experience for everyone, regardless of age, body
38
- size, disability, ethnicity, gender identity and expression, level of experience,
39
- nationality, personal appearance, race, religion, or sexual identity and
40
- orientation.
38
+ **Remove private data before posting**: the token (and any `ssecurity` / `serviceToken`), the serial number, the MAC and
39
+ IP addresses, your Wi-Fi name (`ssid`) and anything else that identifies your home.
41
40
 
42
- ### Our Standards
41
+ ## Contributing code
43
42
 
44
- Examples of behavior that contributes to creating a positive environment
45
- include:
43
+ Pull requests are very welcome, too. Read [AGENTS.md](./AGENTS.md) first: it describes the layout, the commands, how to
44
+ test without hardware, and the gotchas (for humans as well).
46
45
 
47
- * Using welcoming and inclusive language
48
- * Being respectful of differing viewpoints and experiences
49
- * Gracefully accepting constructive criticism
50
- * Focusing on what is best for the community
51
- * Showing empathy towards other community members
46
+ - Open PRs from a feature branch against `main`, with a label (`enhancement`, `bug`, `dependencies`, `documentation`):
47
+ the release notes are generated from them.
48
+ - Every behavioural change needs **unit tests**. Use `createFakeHandle(model, responses)` to replay device responses,
49
+ ideally real captures from users.
50
+ - Before pushing: `npm run lint` (ESLint and Prettier, warnings fail too), `npm test` and `npm run build`.
51
+ - **Licensing**: node-miio is MIT. Don't copy or translate code, mappings or tables from GPL projects (e.g. python-miio).
52
+ Using them as a reference for how a device behaves is fine.
52
53
 
53
- Examples of unacceptable behavior by participants include:
54
+ ## Code of conduct
54
55
 
55
- * The use of sexualized language or imagery and unwelcome sexual attention or
56
- advances
57
- * Trolling, insulting/derogatory comments, and personal or political attacks
58
- * Public or private harassment
59
- * Publishing others' private information, such as a physical or electronic
60
- address, without explicit permission
61
- * Other conduct which could reasonably be considered inappropriate in a
62
- professional setting
63
-
64
- ### Our Responsibilities
65
-
66
- Project maintainers are responsible for clarifying the standards of acceptable
67
- behavior and are expected to take appropriate and fair corrective action in
68
- response to any instances of unacceptable behavior.
69
-
70
- Project maintainers have the right and responsibility to remove, edit, or
71
- reject comments, commits, code, wiki edits, issues, and other contributions
72
- that are not aligned to this Code of Conduct, or to ban temporarily or
73
- permanently any contributor for other behaviors that they deem inappropriate,
74
- threatening, offensive, or harmful.
75
-
76
- ### Scope
77
-
78
- This Code of Conduct applies both within project spaces and in public spaces
79
- when an individual is representing the project or its community. Examples of
80
- representing a project or community include using an official project e-mail
81
- address, posting via an official social media account, or acting as an appointed
82
- representative at an online or offline event. Representation of a project may be
83
- further defined and clarified by project maintainers.
84
-
85
- ### Enforcement
86
-
87
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
88
- reported by contacting the main developer at a@holstenson.se. All
89
- complaints will be reviewed and investigated and will result in a response that
90
- is deemed necessary and appropriate to the circumstances. The project team is
91
- obligated to maintain confidentiality with regard to the reporter of an incident.
92
- Further details of specific enforcement policies may be posted separately.
93
-
94
- Project maintainers who do not follow or enforce the Code of Conduct in good
95
- faith may face temporary or permanent repercussions as determined by other
96
- members of the project's leadership.
97
-
98
- ### Attribution
99
-
100
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
101
- available at [http://contributor-covenant.org/version/1/4][version]
102
-
103
- [homepage]: http://contributor-covenant.org
104
- [version]: http://contributor-covenant.org/version/1/4/
56
+ Be kind and respectful. This project follows the
57
+ [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). Unacceptable behaviour can be
58
+ reported to the maintainer ([@afharo](https://github.com/afharo)).
package/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  <!-- prettier-ignore -->
2
- > [!WARNING]
3
- > **Looking for a new maintainer**
2
+ > [!NOTE]
3
+ > **Beta testers wanted**
4
4
  >
5
- > I no longer own a device supported by this project (my new vacuum supports Matter natively), so I can't test changes against real hardware anymore.
6
- > I'm happy to hand over ownership of the repository and the npm package to anyone who wants to continue its development.
7
- >
8
- > In the meantime, I'll keep addressing the reported issues with AI-assisted development, relying on the automated tests and **your feedback**: please, try the beta releases and report back.
9
- > Interested in taking over? Please, comment on [this issue](https://github.com/afharo/node-miio/issues/18).
5
+ > The maintainer no longer owns most of the supported devices, so changes are developed against automated tests and validated by users on beta releases.
6
+ > If you'd like to help, sign up as a beta tester in the plugin you use ([Homebridge](https://github.com/homebridge-xiaomi-roborock-vacuum/homebridge-xiaomi-roborock-vacuum/issues/1232), [Matterbridge](https://github.com/afharo/matterbridge-xiaomi-roborock/issues/387)) or in [#18](https://github.com/afharo/node-miio/issues/18).
7
+ > See [CONTRIBUTING.md](./CONTRIBUTING.md) for other ways to help. Co-maintainers are welcome too.
10
8
 
11
9
  # miIO Device Library
12
10
 
@@ -96,6 +94,22 @@ npm install -g node-miio
96
94
  const miio = require("node-miio");
97
95
  ```
98
96
 
97
+ The package includes TypeScript declarations. With TypeScript, use `isVacuum()` to narrow the device to a
98
+ `VacuumDevice`, and `instanceof` for the API of a specific implementation:
99
+
100
+ ```typescript
101
+ import * as miio from "node-miio";
102
+ import { isVacuum, Vacuum } from "node-miio";
103
+
104
+ const device = await miio.device({ address, token });
105
+ if (isVacuum(device)) {
106
+ await device.activateCleaning(); // shared by every vacuum
107
+ if (device instanceof Vacuum) {
108
+ await device.startMopWash(); // Roborock only
109
+ }
110
+ }
111
+ ```
112
+
99
113
  Resolve a handle to the device:
100
114
 
101
115
  ```javascript
@@ -254,6 +268,28 @@ To activate both namespaces set `DEBUG` to both:
254
268
  $ DEBUG=miio\*,thing\* miio discover
255
269
  ```
256
270
 
271
+ ### Sending the debug messages to your own logger
272
+
273
+ Apps (e.g. Homebridge or Matterbridge plugins) can send node-miio's debug messages to their own logger, so users don't
274
+ need to set `DEBUG`. Tokens and passwords are redacted from these messages.
275
+
276
+ ```javascript
277
+ const miio = require("node-miio");
278
+
279
+ // The messages of this device (requests, responses, property changes…)
280
+ const device = await miio.device({
281
+ address,
282
+ token,
283
+ logger: { debug: (msg) => log.debug(msg) },
284
+ });
285
+
286
+ // Everything that isn't about a specific device (network, MIoT specs, Xiaomi Cloud…)
287
+ miio.configureLogging({ logger: { debug: (msg) => log.debug(msg) } });
288
+ ```
289
+
290
+ The messages are prefixed with their namespace, e.g. `[thing:miio:1234] <- Message: ...`. The low-level packet details
291
+ (`miio:packet`) are only available through `DEBUG`.
292
+
257
293
  ## Protocol documentation
258
294
 
259
295
  This library is based on the documentation provided by OpenMiHome. See https://github.com/OpenMiHome/mihome-binary-protocol for details. For details
@@ -0,0 +1,10 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ import { type CloudServer } from "../../../lib/cloud/index";
3
+ export declare const command = "devices";
4
+ export declare const description = "List the devices of your Xiaomi account, with their tokens";
5
+ export declare const builder: CommandBuilder;
6
+ export declare const handler: (argv: {
7
+ server?: CloudServer;
8
+ json?: boolean;
9
+ save?: boolean;
10
+ }) => Promise<void>;
@@ -0,0 +1,8 @@
1
+ import type { CommandBuilder } from "yargs";
2
+ export declare const command = "login";
3
+ export declare const description = "Log in to the Xiaomi Cloud (the session is saved, your password is not)";
4
+ export declare const builder: CommandBuilder;
5
+ export declare const handler: (argv: {
6
+ qr?: boolean;
7
+ username?: string;
8
+ }) => Promise<void>;
@@ -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,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,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 {};
@@ -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,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,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 {};
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.XiaomiCloud = exports.CLOUD_SERVERS = void 0;
7
4
  /*
@@ -11,12 +8,12 @@ exports.XiaomiCloud = exports.CLOUD_SERVERS = void 0;
11
8
  * and Xiaomi-Cloud-Map-Extractor (https://github.com/PiotrMachowski/Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor)
12
9
  * Copyright (c) 2020 Piotr Machowski. Licensed under the MIT License.
13
10
  */
14
- const debug_1 = __importDefault(require("debug"));
11
+ const logger_1 = require("../logger");
15
12
  const crypto_1 = require("./crypto");
16
13
  const errors_1 = require("./errors");
17
14
  const http_1 = require("./http");
18
15
  const login_1 = require("./login");
19
- const debug = (0, debug_1.default)("miio:cloud");
16
+ const debug = (0, logger_1.createDebug)("miio:cloud");
20
17
  /** The regional servers of the Xiaomi Cloud */
21
18
  exports.CLOUD_SERVERS = [
22
19
  "cn",