node-miio 0.6.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.
Files changed (91) hide show
  1. package/README.md +4 -0
  2. package/dist/cli/commands/roborock/call.d.ts +10 -0
  3. package/dist/cli/commands/roborock/call.js +34 -0
  4. package/dist/cli/commands/roborock/call.js.map +1 -0
  5. package/dist/cli/commands/roborock/devices.d.ts +8 -0
  6. package/dist/cli/commands/roborock/devices.js +58 -0
  7. package/dist/cli/commands/roborock/devices.js.map +1 -0
  8. package/dist/cli/commands/roborock/login.d.ts +7 -0
  9. package/dist/cli/commands/roborock/login.js +34 -0
  10. package/dist/cli/commands/roborock/login.js.map +1 -0
  11. package/dist/cli/commands/roborock/logout.d.ts +4 -0
  12. package/dist/cli/commands/roborock/logout.js +14 -0
  13. package/dist/cli/commands/roborock/logout.js.map +1 -0
  14. package/dist/cli/commands/roborock/map.d.ts +10 -0
  15. package/dist/cli/commands/roborock/map.js +74 -0
  16. package/dist/cli/commands/roborock/map.js.map +1 -0
  17. package/dist/cli/commands/roborock/robot.d.ts +30 -0
  18. package/dist/cli/commands/roborock/robot.js +61 -0
  19. package/dist/cli/commands/roborock/robot.js.map +1 -0
  20. package/dist/cli/commands/roborock/rooms.d.ts +9 -0
  21. package/dist/cli/commands/roborock/rooms.js +40 -0
  22. package/dist/cli/commands/roborock/rooms.js.map +1 -0
  23. package/dist/cli/commands/roborock.d.ts +5 -0
  24. package/dist/cli/commands/roborock.js +55 -0
  25. package/dist/cli/commands/roborock.js.map +1 -0
  26. package/dist/cli/index.js +2 -0
  27. package/dist/cli/index.js.map +1 -1
  28. package/dist/lib/cloud/client.d.ts +18 -5
  29. package/dist/lib/cloud/client.js +17 -7
  30. package/dist/lib/cloud/client.js.map +1 -1
  31. package/dist/lib/cloud/device_cache.d.ts +38 -0
  32. package/dist/lib/cloud/device_cache.js +59 -0
  33. package/dist/lib/cloud/device_cache.js.map +1 -0
  34. package/dist/lib/cloud/index.d.ts +2 -1
  35. package/dist/lib/cloud/index.js +4 -1
  36. package/dist/lib/cloud/index.js.map +1 -1
  37. package/dist/lib/device_info.d.ts +6 -0
  38. package/dist/lib/devices/vacuums/vacuum.d.ts +3 -3
  39. package/dist/lib/devices/vacuums/vacuum.js +13 -3
  40. package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
  41. package/dist/lib/devices/vacuums/vacuum_modes.d.ts +2 -0
  42. package/dist/lib/devices/vacuums/vacuum_modes.js +15 -0
  43. package/dist/lib/devices/vacuums/vacuum_modes.js.map +1 -1
  44. package/dist/lib/index.d.ts +1 -0
  45. package/dist/lib/index.js +1 -0
  46. package/dist/lib/index.js.map +1 -1
  47. package/dist/lib/logger.js +1 -1
  48. package/dist/lib/logger.js.map +1 -1
  49. package/dist/lib/management.d.ts +2 -2
  50. package/dist/lib/management.js.map +1 -1
  51. package/dist/lib/roborock/device.d.ts +118 -0
  52. package/dist/lib/roborock/device.js +273 -0
  53. package/dist/lib/roborock/device.js.map +1 -0
  54. package/dist/lib/roborock/errors.d.ts +18 -0
  55. package/dist/lib/roborock/errors.js +37 -0
  56. package/dist/lib/roborock/errors.js.map +1 -0
  57. package/dist/lib/roborock/hawk.d.ts +39 -0
  58. package/dist/lib/roborock/hawk.js +48 -0
  59. package/dist/lib/roborock/hawk.js.map +1 -0
  60. package/dist/lib/roborock/index.d.ts +9 -0
  61. package/dist/lib/roborock/index.js +36 -0
  62. package/dist/lib/roborock/index.js.map +1 -0
  63. package/dist/lib/roborock/local_connection.d.ts +72 -0
  64. package/dist/lib/roborock/local_connection.js +232 -0
  65. package/dist/lib/roborock/local_connection.js.map +1 -0
  66. package/dist/lib/roborock/map_response.d.ts +26 -0
  67. package/dist/lib/roborock/map_response.js +104 -0
  68. package/dist/lib/roborock/map_response.js.map +1 -0
  69. package/dist/lib/roborock/message.d.ts +110 -0
  70. package/dist/lib/roborock/message.js +313 -0
  71. package/dist/lib/roborock/message.js.map +1 -0
  72. package/dist/lib/roborock/mqtt.d.ts +119 -0
  73. package/dist/lib/roborock/mqtt.js +305 -0
  74. package/dist/lib/roborock/mqtt.js.map +1 -0
  75. package/dist/lib/roborock/rooms.d.ts +17 -0
  76. package/dist/lib/roborock/rooms.js +23 -0
  77. package/dist/lib/roborock/rooms.js.map +1 -0
  78. package/dist/lib/roborock/session_store.d.ts +21 -0
  79. package/dist/lib/roborock/session_store.js +52 -0
  80. package/dist/lib/roborock/session_store.js.map +1 -0
  81. package/dist/lib/roborock/web_api.d.ts +142 -0
  82. package/dist/lib/roborock/web_api.js +334 -0
  83. package/dist/lib/roborock/web_api.js.map +1 -0
  84. package/docs/cloud.md +11 -0
  85. package/docs/roborock.md +91 -0
  86. package/package.json +2 -1
  87. package/snapshots/vacuum-specs.json.gz +0 -0
  88. package/.claude/settings.json +0 -5
  89. package/.claude/skills/release/SKILL.md +0 -73
  90. package/AGENTS.md +0 -140
  91. package/CONTRIBUTING.md +0 -58
package/AGENTS.md DELETED
@@ -1,140 +0,0 @@
1
- # AGENTS.md
2
-
3
- Guidance for AI coding agents (and humans) working on `node-miio`.
4
-
5
- ## Context
6
-
7
- - `node-miio` is the miIO/MIoT protocol library used by
8
- [homebridge-xiaomi-roborock-vacuum](https://github.com/homebridge-xiaomi-roborock-vacuum/homebridge-xiaomi-roborock-vacuum)
9
- and [matterbridge-xiaomi-roborock](https://github.com/afharo/matterbridge-xiaomi-roborock).
10
- - **The maintainer no longer owns test hardware** (see [#18](https://github.com/afharo/node-miio/issues/18)).
11
- Every behavioural change must be covered by unit tests that replay device responses, and be released as a beta for users to validate.
12
- - Changes are delivered as PRs from feature branches into `main`. Do not push to `main` directly.
13
- - **Label every PR** when creating it, so `.github/release.yml` can group the release notes:
14
- `enhancement` (features), `bug` (fixes), `dependencies` (deps / Node.js engines), `documentation` (docs only).
15
- PRs labelled `release` (version bumps) are excluded from the notes.
16
-
17
- ## Commands
18
-
19
- ```sh
20
- npm ci
21
- npm run lint # eslint --max-warnings=0: warnings fail CI too
22
- npm test # jest (babel-jest: tests are NOT type-checked, `npm run build` is)
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
25
- node dist/cli/index.js --help # smoke-test the CLI after building
26
- ```
27
-
28
- CI (`.github/workflows/build.yml`) runs lint, test and build on Node 22/24/26. The minimum is Node 22.12 (`engines`):
29
- the ESM-only yargs 18 is loaded with `require()`, which needs `require(esm)` support.
30
-
31
- ## Layout
32
-
33
- - `src/lib/index.ts`: public API (`device()`, `devices()`, `browse()`, `models` and the exported device classes).
34
- - `src/lib/connect_to_device.ts`: resolves a model to a class. Exact match in `src/lib/models.ts` first, then a regex fallback
35
- (`*.vacuum.*` → `Vacuum` / `ViomiVacuum` / `DreameVacuum`), then the generic `Device`.
36
- - `src/lib/device.ts`: base class (`MiioApi`). Properties are declared with `defineProperty(rawName, { name, mapper, siid?, piid? })`
37
- and loaded by `loadProperties` (default: `get_prop`; vacuums override it).
38
- - `src/lib/device_info.ts`: low-level transport (handshake, encryption, retries).
39
- - `src/lib/protocol.ts`: typed map of RPC methods → params/response.
40
- - `src/lib/devices/**`: device implementations. The TypeScript conversion is in progress; some files are still `.js`.
41
- - `src/cli/**`: the `node-miio` CLI (yargs). Commands are registered explicitly in `src/cli/index.ts`
42
- (`commandDir` doesn't work with the ESM-only yargs 18).
43
-
44
- ## Testing without hardware
45
-
46
- - Use `createFakeHandle(model, responses)` from `src/lib/test_utils.test.mock.ts` to build a device that replays responses.
47
- Unexpected RPC methods reject, so tests fail loudly. Assert sent calls with `sentCalls(call)`.
48
- - Put recorded responses under `src/lib/__fixtures__/<model>/<method>.json` (excluded from the npm package).
49
- Prefer real captures from users' bug reports (`node-miio protocol call <ip> <method>`); scrub tokens, serial numbers and IPs.
50
- - Commands using `refresh`/`refreshDelay` wait on timers: use fake timers and `jest.advanceTimersByTimeAsync`.
51
- - `src/lib/modules_load.test.ts` loads every module in isolation. It catches broken mixins and circular imports.
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
-
65
- ## Linting
66
-
67
- - JSDoc is optional. When present, it must be correct (`check-param-names`, `require-param`, `check-tag-names`).
68
- In `.ts` files, types come from TypeScript, so JSDoc types are not allowed (`jsdoc/no-types`). In `.js` files, `@param {type}` is required.
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`).
72
-
73
- ## Gotchas learned the hard way
74
-
75
- - **abstract-things mixins**: capabilities built with `Thing.mixin(...)` must be exported as values
76
- (`export const X = Thing.mixin(...)`), never as `class X extends Thing.mixin(...) {}`, which throws at load time.
77
- - **Circular imports**: `device` → `management` → `connect_to_device` → `placeholder` → `device`. `management.ts` lazy-loads
78
- `connect_to_device` for that reason. Keep it that way.
79
- - **The vacuum type is spelled `vaccuum`** by abstract-things (`device.matches("type:vaccuum")`). It's not a typo in the consumers. Don't "fix" it.
80
- - Roborock `get_status` / `get_consumable` respond with a single-item array (`[{...}]`).
81
- - Properties whose mapped value is `undefined`/`null` are not stored on first load (`deep-equal` treats them as equal).
82
- - Legacy Roborock models (`roborock.vacuum.*`, `rockrobo.vacuum.*`) speak the **legacy miIO** command set (`get_status`, `app_start`, …).
83
- Their MIoT specs on miot-spec.org are stubs, and their fan-speed values differ from the spec (and change with the firmware).
84
-
85
- ## Legacy Roborock
86
-
87
- - Fan speeds / water levels of legacy miIO models live in `src/lib/devices/vacuums/vacuum_modes.ts` (`resolveVacuumModes(model, fw)`),
88
- moved from the plugins' `models/` folders. When a user reports wrong speeds, fix them **here**, with a test in `vacuum_modes.test.ts`.
89
- - `Vacuum.fanSpeeds()` reads `fw_ver` from `miIO.info` once (some models changed their values in newer firmwares, e.g. S5 ≥ 3.5.7).
90
- - All vacuum classes expose the same async `fanSpeeds()` / `waterBoxModes()` API returning `{ value, name }[]`.
91
- There's no "Off" entry: that's a plugin/UI concept.
92
- - `cleanRooms(ids, { repeat })` only sends the object format (`[{ segments, repeat }]`) when `repeat > 1`, because older firmwares only accept the list.
93
-
94
- ## Device specs (MIoT)
95
-
96
- - Model → URN: `https://miot-spec.org/miot-spec-v2/instances?status=all` (~7 MB). Prefer `released` and the highest `version`.
97
- - Spec: `https://miot-spec.org/miot-spec-v2/instance?type=<urn>` (`services[].iid` = siid, `properties[].iid` = piid, `actions[].iid` = aiid).
98
- - Translations: `https://miot-spec.org/instance/v2/multiLanguage?urn=<urn>`.
99
- - home.miot-spec.com is a UI over the same data. Don't depend on it.
100
-
101
- Implementation (`src/lib/miot/`):
102
-
103
- - `spec_client.ts` (`MiotSpecClient`): resolves specs from `specDir` → fresh cache → network → stale cache → bundled snapshot.
104
- Configure it globally with `configureMiotSpecs({ offline, cacheDir, specDir, ttlMs })`. `MIIO_OFFLINE=1` and `MIIO_CACHE_DIR` also work.
105
- - `miot_spec.ts` (`MiotSpecIndex`): lookups by **standard** (`miot-spec-v2`) names only. Vendor namespaces are ignored.
106
- Don't name files `spec.ts`/`*.spec.ts`: jest picks them up as test files.
107
- - `miot_api.ts`: `getProperties` (batched by 10), `setProperty`, `callAction`. These throw `MiotError` when `code !== 0`.
108
- - `devices/vacuums/miot-vacuum.ts` (`MiotVacuum`): spec-driven vacuum. Heuristics are based on a survey of all ~1,000 vacuum specs:
109
- - Many specs carry placeholder value-lists (`[Auto, Level1]`). Modes need ≥3 entries and a writable property.
110
- - Fan speed: first match of `fan-level`, `suction-level`, `mode` (unless its values are cleaning types like Sweep/Mop), `speed-level`.
111
- - Water: `mop-water-output-level`, `target-water-level`, `water-level`.
112
- - Cleaning type (`cleaningTypes()` / `setCleaningType()`): `sweep-mop-type` (Sweep / Mop / Sweep Mop / Sweep Before Mopping),
113
- or `mode` when all its values are sweep/mop types (e.g. ijai). Never the property used for the fan speed.
114
- - `vacuum:status` descriptions are normalized by `normalizeState()` to the state names used by the legacy classes.
115
- - Routing (`connect_to_device.ts`): `roborock.*` and `rockrobo.*` always use the legacy classes.
116
- Other `*.vacuum.*` models use `MiotVacuum` only if a spec exists **and** the device answers `get_properties` for `vacuum:status`.
117
- Otherwise they fall back to the previous behaviour (`ViomiVacuum` for `viomi.*`, `DreameVacuum` for `dreame.*`, `Vacuum` for the rest).
118
- - Viomi has both kinds of models. Older ones (v3/v6/v7/v8/v9/v10/v31) publish placeholder specs (`isPlaceholderSpec`) and stay on `ViomiVacuum`.
119
- Newer ones (e.g. v13, v18) are real MIoT devices: the legacy calls time out for them (homebridge issues #328, #443).
120
- The placeholder rule only applies to Viomi. For other brands a small spec can still be a genuine MIoT device.
121
- - Pinned in `models.ts`: `dreame.vacuum.mc1808` → `DreameVacuum`, `viomi.vacuum.v7`/`v8` → `ViomiVacuum`.
122
- - Snapshot: `npm run snapshot` (`scripts/update-spec-snapshot.mjs`) writes `snapshots/vacuum-specs.json.gz` (~2 MB, every vacuum spec).
123
- It's gitignored and regenerated by the publish workflows, so every release carries a point-in-time copy for air-gapped setups.
124
- - CLI: `node-miio spec <model> [--offline] [--json] [--spec-dir dir]`. Ask users for its output in bug reports.
125
- - Test fixtures: real specs in `src/lib/__fixtures__/miot/<model>.json`.
126
-
127
- ## Licensing (important)
128
-
129
- `node-miio` is MIT. [python-miio](https://github.com/rytilahti/python-miio) is **GPL-3.0**. Use it as a behavioural
130
- reference only (which commands exist, what they do). **Never copy or translate its code, mappings or tables.**
131
- Implement from the miot-spec data, protocol documentation (e.g. marcelrv/XiaomiRobotVacuumProtocol) and captured traffic.
132
- Other projects (openHAB: EPL-2.0; hass-xiaomi-miot: Apache-2.0) need attribution if anything is reused. Prefer reimplementing.
133
- Piotr Machowski's Xiaomi-cloud-tokens-extractor and Xiaomi-Cloud-Map-Extractor are **MIT**: they may be ported, keeping the
134
- attribution header in the ported files (`src/lib/cloud/`) and the notice in `LICENSE.md`.
135
-
136
- ## Xiaomi Cloud (`src/lib/cloud/`)
137
-
138
- Opt-in only: nothing in the local control paths may require the cloud. Tests use the fake server in
139
- `cloud.test.mock.ts` (no network); the crypto is checked against vectors generated by the Python reference
140
- (`__fixtures__/cloud/crypto-vectors.json`). Never log passwords, tokens, `ssecurity` or `serviceToken`.
package/CONTRIBUTING.md DELETED
@@ -1,58 +0,0 @@
1
- # Contributing
2
-
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:
6
-
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)
10
-
11
- ## Become a beta tester
12
-
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
-
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)
18
-
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
-
22
- ## Share what your device reports
23
-
24
- Supporting a model or a feature starts with knowing what the device answers. When opening an issue, include:
25
-
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.
35
-
36
- Replies are turned into test fixtures (`src/lib/__fixtures__/`), so the behaviour stays covered without the device.
37
-
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.
40
-
41
- ## Contributing code
42
-
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).
45
-
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.
53
-
54
- ## Code of conduct
55
-
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)).