meross-iot 0.9.1 → 0.10.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 (115) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +60 -67
  3. package/index.d.ts +330 -3502
  4. package/index.js +11 -112
  5. package/lib/{controller/features/alarm-feature.js → abilities/alarm.js} +27 -17
  6. package/lib/{controller/features/child-lock-feature.js → abilities/child-lock.js} +7 -5
  7. package/lib/{controller/features/config-feature.js → abilities/config.js} +8 -6
  8. package/lib/{controller/features/consumption-feature.js → abilities/consumption.js} +14 -18
  9. package/lib/{controller/features/control-feature.js → abilities/control.js} +10 -7
  10. package/lib/abilities/diffuser.js +192 -0
  11. package/lib/{controller/features/digest-timer-feature.js → abilities/digest-timer.js} +6 -5
  12. package/lib/{controller/features/digest-trigger-feature.js → abilities/digest-trigger.js} +6 -5
  13. package/lib/{controller/features/dnd-feature.js → abilities/dnd.js} +10 -11
  14. package/lib/{controller/features/electricity-feature.js → abilities/electricity.js} +20 -24
  15. package/lib/{controller/features/encryption-feature.js → abilities/encryption.js} +7 -8
  16. package/lib/{controller/features/garage-feature.js → abilities/garage.js} +47 -95
  17. package/lib/{controller/features/hub-feature.js → abilities/hub.js} +75 -52
  18. package/lib/{controller/features/light-feature.js → abilities/light.js} +137 -148
  19. package/lib/{controller/features/presence-sensor-feature.js → abilities/presence.js} +147 -91
  20. package/lib/abilities/roller-shutter.js +236 -0
  21. package/lib/{controller/features/runtime-feature.js → abilities/runtime.js} +6 -5
  22. package/lib/{controller/features/screen-feature.js → abilities/screen.js} +7 -5
  23. package/lib/{controller/features/sensor-history-feature.js → abilities/sensor-history.js} +7 -5
  24. package/lib/{controller/features/smoke-config-feature.js → abilities/smoke-config.js} +7 -5
  25. package/lib/abilities/spray.js +122 -0
  26. package/lib/{controller/features/system-feature.js → abilities/system.js} +59 -25
  27. package/lib/{controller/features/temp-unit-feature.js → abilities/temp-unit.js} +9 -7
  28. package/lib/{controller/features/thermostat-feature.js → abilities/thermostat.js} +220 -258
  29. package/lib/{controller/features/timer-feature.js → abilities/timer.js} +137 -24
  30. package/lib/abilities/toggle.js +149 -0
  31. package/lib/{controller/features/trigger-feature.js → abilities/trigger.js} +127 -34
  32. package/lib/{http-api.js → api/client.js} +55 -123
  33. package/lib/{model → api}/constants.js +4 -0
  34. package/lib/{model/http → api}/device.js +12 -12
  35. package/lib/{model/http → api}/error-codes.js +1 -1
  36. package/lib/{model/http → api}/subdevice.js +10 -10
  37. package/lib/{model/channel-info.js → device/channel.js} +4 -0
  38. package/lib/device/device.js +1618 -0
  39. package/lib/{device-factory.js → device/factory.js} +121 -120
  40. package/lib/{controller/hub-device.js → device/hubdevice.js} +17 -44
  41. package/lib/{device-registry.js → device/registry.js} +4 -44
  42. package/lib/{controller → device}/subdevice.js +97 -150
  43. package/lib/dispatcher.js +257 -0
  44. package/lib/exception.js +211 -0
  45. package/lib/meross.js +426 -0
  46. package/lib/{model/push → push}/factory.js +14 -10
  47. package/lib/{model/push → push}/generic.js +24 -1
  48. package/lib/{model/push → push}/index.js +2 -2
  49. package/lib/{model/states → states}/diffuser-light-state.js +1 -1
  50. package/lib/{model/states → states}/index.js +1 -1
  51. package/lib/{model/states → states}/light-state.js +1 -1
  52. package/lib/utilities/cache.js +51 -0
  53. package/lib/utilities/conversion.js +3 -3
  54. package/lib/utilities/heartbeat.js +1 -1
  55. package/lib/utilities/options.js +25 -5
  56. package/lib/utilities/request-queue.js +2 -2
  57. package/lib/utilities/state-ordering.js +57 -0
  58. package/lib/utilities/timer.js +14 -18
  59. package/lib/utilities/trigger.js +15 -17
  60. package/manager/auth.js +157 -0
  61. package/manager/base.js +18 -0
  62. package/{lib/managers → manager}/devices.js +179 -177
  63. package/{lib/managers → manager}/http.js +46 -62
  64. package/{lib/managers → manager}/mqtt.js +153 -112
  65. package/manager/registry.js +26 -0
  66. package/manager/statistics.js +114 -0
  67. package/{lib/managers → manager}/subscription.js +28 -248
  68. package/manager/transport.js +260 -0
  69. package/package.json +4 -2
  70. package/lib/controller/device.js +0 -1482
  71. package/lib/controller/features/diffuser-feature.js +0 -287
  72. package/lib/controller/features/roller-shutter-feature.js +0 -332
  73. package/lib/controller/features/spray-feature.js +0 -181
  74. package/lib/controller/features/toggle-feature.js +0 -188
  75. package/lib/error-budget.js +0 -138
  76. package/lib/manager.js +0 -510
  77. package/lib/managers/statistics.js +0 -158
  78. package/lib/managers/transport.js +0 -217
  79. package/lib/model/exception.js +0 -786
  80. package/lib/model/http/exception.js +0 -204
  81. package/lib/utilities/debug.js +0 -153
  82. /package/lib/{model/enums.js → enums.js} +0 -0
  83. /package/lib/{model/push → push}/alarm.js +0 -0
  84. /package/lib/{model/push → push}/bind.js +0 -0
  85. /package/lib/{model/push → push}/common.js +0 -0
  86. /package/lib/{model/push → push}/diffuser-light.js +0 -0
  87. /package/lib/{model/push → push}/diffuser-spray.js +0 -0
  88. /package/lib/{model/push → push}/hub-battery.js +0 -0
  89. /package/lib/{model/push → push}/hub-mts100-all.js +0 -0
  90. /package/lib/{model/push → push}/hub-mts100-mode.js +0 -0
  91. /package/lib/{model/push → push}/hub-mts100-temperature.js +0 -0
  92. /package/lib/{model/push → push}/hub-online.js +0 -0
  93. /package/lib/{model/push → push}/hub-sensor-alert.js +0 -0
  94. /package/lib/{model/push → push}/hub-sensor-all.js +0 -0
  95. /package/lib/{model/push → push}/hub-sensor-smoke.js +0 -0
  96. /package/lib/{model/push → push}/hub-sensor-temphum.js +0 -0
  97. /package/lib/{model/push → push}/hub-subdevicelist.js +0 -0
  98. /package/lib/{model/push → push}/hub-togglex.js +0 -0
  99. /package/lib/{model/push → push}/online.js +0 -0
  100. /package/lib/{model/push → push}/presence-study.js +0 -0
  101. /package/lib/{model/push → push}/sensor-latestx.js +0 -0
  102. /package/lib/{model/push → push}/timerx.js +0 -0
  103. /package/lib/{model/push → push}/togglex.js +0 -0
  104. /package/lib/{model/push → push}/triggerx.js +0 -0
  105. /package/lib/{model/push → push}/unbind.js +0 -0
  106. /package/lib/{model/push → push}/water-leak.js +0 -0
  107. /package/lib/{model/states → states}/diffuser-spray-state.js +0 -0
  108. /package/lib/{model/states → states}/garage-door-state.js +0 -0
  109. /package/lib/{model/states → states}/presence-sensor-state.js +0 -0
  110. /package/lib/{model/states → states}/roller-shutter-state.js +0 -0
  111. /package/lib/{model/states → states}/spray-state.js +0 -0
  112. /package/lib/{model/states → states}/thermostat-state.js +0 -0
  113. /package/lib/{model/states → states}/timer-state.js +0 -0
  114. /package/lib/{model/states → states}/toggle-state.js +0 -0
  115. /package/lib/{model/states → states}/trigger-state.js +0 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,61 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.10.0] - 2026-05-19
9
+
10
+ ### Added
11
+ - `Meross.authenticate()` — authenticate and return a manager without connecting to the cloud or initializing devices
12
+ - `Meross.connect()` — static entry point that authenticates and connects in one step
13
+ - Multi-channel helpers on toggle, timer, and trigger abilities: `getAll()` aggregates state across all device channels; timer and trigger also expose `count()`
14
+ - `getDeviceChannelIds()` utility for consistent channel enumeration from capabilities or device metadata
15
+ - Namespace dispatcher with header-timestamp ordering gate for SETACK, GETACK, and PUSH state updates
16
+ - Shared cache helpers (`readCache`, `getCachedOrFetch`) used by ability `get()` methods
17
+ - Unit test suite (198 tests) covering abilities, dispatcher, push notifications, authentication, and public module surface
18
+ - `manager.mqtt.connections` — exposes active MQTT connection map for diagnostics
19
+
20
+ ### Changed
21
+ - **BREAKING**: Renamed `ManagerMeross` to `Meross` (default export)
22
+ - `const Meross = require('meross-iot')` replaces `const ManagerMeross = require('meross-iot')`
23
+ - Direct construction requires an authenticated HTTP client; use `Meross.authenticate()` or `Meross.connect()` as entry points
24
+ - **BREAKING**: Removed public `MerossHttpClient` export
25
+ - Use `Meross.authenticate()` for credential exchange and token reuse via `meross.getTokenData()`
26
+ - **BREAKING**: Consolidated error classes into a smaller hierarchy with string `code` discriminators
27
+ - Exported: `MerossError`, `MerossAuthError`, `MerossDeviceError`, `MerossApiError`, `MerossNetworkError`
28
+ - Removed granular exports such as `MerossErrorAuthentication`, `MerossErrorTokenExpired`, `MerossErrorCommandTimeout`, `MerossErrorValidation`, etc.
29
+ - Catch category errors with `instanceof` and inspect `error.code` for specific handling (e.g. `TOKEN_EXPIRED`, `VALIDATION_ERROR`, `COMMAND_TIMEOUT`)
30
+ - Removed public `mapErrorCodeToError` export
31
+ - **BREAKING**: Renamed `device.getUnifiedState()` to `device.getState()`
32
+ - State is now derived from dispatcher namespace descriptors rather than hand-maintained aggregation
33
+ - **BREAKING**: Unified device initialization events
34
+ - Device emits `ready` (replacing `deviceInitialized`); manager emits `deviceReady` when a device finishes bootstrap
35
+ - `device.ready()` promise API unchanged
36
+ - **BREAKING**: Device abilities are initialized conditionally based on supported namespaces
37
+ - Unsupported features are absent (`undefined`) rather than present with stub methods
38
+ - **BREAKING**: Transport and statistics are accessed exclusively via sub-managers
39
+ - Use `meross.transport` for mode selection, error budgets, and request queuing
40
+ - Use `meross.statistics` for HTTP/MQTT stats (`enable()`, `getHttpStats()`, `getMqttStats()`)
41
+ - **BREAKING**: Trimmed public module exports to documented API surface
42
+ - Removed exports for state classes, push notification classes, `TimerUtils`, `TriggerUtils`, `createDebugUtils`, `ManagerSubscription`, and `MerossHttpClient`
43
+ - Removed `ThermostatWorkingMode` and `ThermostatModeBState` from package root exports (still available internally)
44
+ - **BREAKING**: Internal package layout restructured (no import-path stability for deep requires)
45
+ - `lib/controller/features/` → `lib/abilities/`
46
+ - `lib/managers/` → `manager/`
47
+ - `lib/controller/` → `lib/device/`
48
+ - `lib/http-api.js` → `lib/api/client.js`
49
+ - Subdevice state updates now pass through the same ordering gate as base devices, preventing stale hub sensor payloads from overwriting fresher per-namespace data
50
+ - Rewrote TypeScript definitions to match the simplified public API
51
+ - Updated all examples for the new connect/authenticate flow and ability-based device control
52
+
53
+ ### Fixed
54
+ - Rewrote `publishMessage` without an async Promise executor
55
+ - HTTP API status errors are routed through `mapErrorCodeToError` consistently
56
+ - Exposed `manager.mqtt.connections` and aligned `disconnectAll()` routing through the mqtt getter
57
+
58
+ ### Removed
59
+ - Standalone `lib/error-budget.js` (error budget logic lives on `ManagerTransport`)
60
+ - `lib/utilities/debug.js` and `createDebugUtils` export
61
+ - Internal ability `_update*` test hooks; state is exercised through dispatcher shims in tests
62
+
8
63
  ## [0.9.1] - 2026-01-22
9
64
 
10
65
  ### Fixed
package/README.md CHANGED
@@ -26,65 +26,42 @@ The library can control devices locally via HTTP or via cloud MQTT server.
26
26
  npm install meross-iot@alpha
27
27
 
28
28
  # Or install specific version
29
- npm install meross-iot@0.9.1
29
+ npm install meross-iot@0.10.0
30
30
  ```
31
31
 
32
32
  ## Usage & Documentation
33
33
 
34
- Refer to the [example/README.md](example/README.md) for detailed usage instructions, or simply have a look at the `/example` directory.
34
+ Runnable examples live in the GitHub repo under [`packages/meross-iot/example/`](https://github.com/Doekse/merossiot/tree/main/packages/meross-iot/example). See [example/README.md](https://github.com/Doekse/merossiot/blob/main/packages/meross-iot/example/README.md) for the full table (not included in the npm tarball).
35
35
 
36
36
  If you are really impatient to use this library, refer to the following snippet of code that looks for a device and turns it on/off.
37
37
 
38
38
  ```javascript
39
- const { ManagerMeross, MerossHttpClient } = require('meross-iot');
39
+ const Meross = require('meross-iot');
40
40
 
41
41
  (async () => {
42
- // Create HTTP client using factory method
43
- const httpClient = await MerossHttpClient.fromUserPassword({
42
+ const meross = await Meross.connect({
44
43
  email: 'your@email.com',
45
- password: 'yourpassword'
44
+ password: 'yourpassword',
46
45
  });
47
46
 
48
- // Create manager with HTTP client
49
- const meross = new ManagerMeross({
50
- httpClient: httpClient
51
- });
52
-
53
- // Listen for device events
54
- meross.on('deviceInitialized', (deviceId, device) => {
55
- console.log(`Device found: ${device.name} (${device.deviceType})`);
56
- });
57
-
58
- // Connect and discover devices
59
- await meross.connect();
60
-
61
- // Find a device and control it
62
47
  const devices = meross.devices.list();
63
48
  if (devices.length > 0) {
64
49
  const device = devices[0];
65
-
66
- // Example: Toggle a switch
67
50
  if (device.toggle) {
68
- await device.toggle.set({ channel: 0, on: true }); // Turn on channel 0
51
+ await device.toggle.set({ channel: 0, on: true });
69
52
  }
70
53
  }
71
54
  })();
72
55
  ```
73
56
 
74
- The `example/` directory contains focused examples for different use cases:
75
- - **`basic-usage.js`** - Simple connection and device discovery
76
- - **`device-control.js`** - Controlling switches, lights, and monitoring devices
77
- - **`event-handling.js`** - Handling events from devices and the manager
78
- - **`subscription-manager.js`** - Automatic polling and unified update streams with ManagerSubscription
79
- - **`token-reuse.js`** - Saving and reusing authentication tokens
80
- - **`statistics.js`** - Enabling and viewing API call statistics
81
- - **`error-handling.js`** - Comprehensive error handling and MFA
82
- - **`hub-devices.js`** - Working with hub devices and subdevices
83
- - **`transport-modes.js`** - Understanding different transport modes
84
- - **`multiple-accounts.js`** - Using multiple Meross accounts simultaneously
85
- - **`factory-pattern-usage.js`** - Recommended factory pattern for creating HTTP clients and managers
86
- - **`timer-usage.js`** - Creating and managing device timers
87
- - **`selective-initialization.js`** - Selectively initializing devices and subdevices
57
+ Clone the repo or browse GitHub for runnable scripts. Highlights:
58
+
59
+ - **`basic-usage.js`** `Meross.connect()` and list devices
60
+ - **`authenticate.js`** `Meross.authenticate()` then selective `connect()`
61
+ - **`device-control.js`** Feature objects: `toggle`, `light`, `electricity`, `system`
62
+ - **`device-discovery.js`** `discover` / `discoverSubdevices` and `initializeDevice`
63
+ - **`subscription-manager.js`** `meross.subscription` polling and list updates
64
+ - **`token-reuse.js`** Persist `getTokenData()` between runs
88
65
 
89
66
  ## Adding and Removing Devices
90
67
 
@@ -92,21 +69,21 @@ You can dynamically add and remove devices from the manager after initialization
92
69
 
93
70
  ```javascript
94
71
  // Add a single device
95
- const device = await manager.devices.initializeDevice('device-uuid');
72
+ const device = await meross.devices.initializeDevice('device-uuid');
96
73
 
97
74
  // Add a subdevice (hub will be auto-initialized if needed)
98
- const subdevice = await manager.devices.initializeDevice({
99
- hubUuid: 'hub-uuid',
100
- id: 'subdevice-id'
75
+ const subdevice = await meross.devices.initializeDevice({
76
+ hubUuid: 'hub-uuid',
77
+ id: 'subdevice-id'
101
78
  });
102
79
 
103
80
  // Remove a device
104
- const removed = await manager.devices.remove('device-uuid');
81
+ const removed = await meross.devices.remove('device-uuid');
105
82
 
106
83
  // Remove a subdevice
107
- const removed = await manager.devices.remove({
108
- hubUuid: 'hub-uuid',
109
- id: 'subdevice-id'
84
+ const removed = await meross.devices.remove({
85
+ hubUuid: 'hub-uuid',
86
+ id: 'subdevice-id'
110
87
  });
111
88
  ```
112
89
 
@@ -114,32 +91,29 @@ When removing a hub device, all its subdevices are automatically removed as well
114
91
 
115
92
  ## API Organization
116
93
 
117
- The library follows a modular architecture with specialized managers for different concerns:
94
+ The library follows a modular architecture with specialized managers on the connected `Meross` instance:
118
95
 
119
- - **`manager.devices`** - Device discovery, initialization, and lifecycle management
120
- - **`manager.mqtt`** - MQTT connection management and message publishing
121
- - **`manager.http`** - LAN HTTP communication with devices
122
- - **`manager.transport`** - Transport mode selection and message routing
123
- - **`manager.subscription`** - Automatic polling and unified update streams
96
+ - **`meross.devices`** device discovery, initialization, and lifecycle management
97
+ - **`meross.mqtt`** MQTT connection management and message publishing
98
+ - **`meross.http`** LAN HTTP communication with devices
99
+ - **`meross.transport`** transport mode selection and message routing
100
+ - **`meross.subscription`** automatic polling and unified update streams
101
+ - **`meross.statistics`** — optional HTTP/MQTT request diagnostics
124
102
 
125
- This organization makes the API more discoverable and easier to use. For example:
103
+ Most apps use feature objects on devices (`device.toggle.set()`, etc.). Lower-level managers (`mqtt`, `http`, `transport`) remain available for advanced use:
126
104
 
127
105
  ```javascript
128
- // Discover devices without initializing
129
- const availableDevices = await manager.devices.discover({ onlineOnly: true });
106
+ // Discover devices without initializing (after Meross.authenticate)
107
+ const availableDevices = await meross.devices.discover({ onlineOnly: true });
130
108
 
131
- // Initialize devices
132
- const count = await manager.devices.initialize();
109
+ // Initialize all or selected devices
110
+ const count = await meross.devices.initialize();
133
111
 
134
- // Encode and send a message via MQTT
135
- const data = manager.mqtt.encode('GET', 'Appliance.Control.ToggleX', {}, device.uuid);
136
- manager.mqtt.send(device, data);
112
+ // Prefer feature API for everyday control
113
+ await device.toggle.set({ channel: 0, on: true });
137
114
 
138
- // Send a message via LAN HTTP
139
- await manager.http.send(device, '192.168.1.100', data);
140
-
141
- // Use transport manager for automatic routing
142
- await manager.transport.request(device, '192.168.1.100', data);
115
+ // Transport mode (MQTT vs LAN-first)
116
+ meross.transport.defaultMode = Meross.TransportMode.LAN_HTTP_FIRST;
143
117
  ```
144
118
 
145
119
  ## Supported Devices
@@ -177,14 +151,33 @@ Please create an issue on GitHub and include:
177
151
 
178
152
  ## Changelog
179
153
 
154
+ See **[CHANGELOG.md](CHANGELOG.md)** for the full release history.
155
+
156
+ ### [0.10.0] - 2026-05-19
157
+
158
+ Major API simplification release. Highlights:
159
+
160
+ #### Added
161
+ - `Meross.authenticate()` and `Meross.connect()` static entry points
162
+ - Multi-channel `getAll()` on toggle, timer, and trigger abilities
163
+ - Namespace dispatcher with header-timestamp ordering for state updates
164
+ - Unit test suite (198 tests)
165
+
166
+ #### Changed
167
+ - **BREAKING**: `ManagerMeross` → `Meross`; removed public `MerossHttpClient` export
168
+ - **BREAKING**: Consolidated error classes (`MerossAuthError`, `MerossDeviceError`, etc.) with string `code` discriminators
169
+ - **BREAKING**: `device.getUnifiedState()` → `device.getState()`; `deviceInitialized` → `ready` / `deviceReady`
170
+ - **BREAKING**: Conditional ability initialization; trimmed public module exports
171
+ - Internal layout: `lib/abilities/`, `manager/`, `lib/device/`
172
+
173
+ <details>
174
+ <summary>Older releases</summary>
175
+
180
176
  ### [0.9.1] - 2026-01-22
181
177
 
182
178
  #### Fixed
183
179
  - Improve heartbeat offline detection by using response silence (≥ heartbeat interval) instead of treating individual command errors/timeouts as offline signals
184
180
 
185
- <details>
186
- <summary>Older</summary>
187
-
188
181
  ### [0.9.0] - 2026-01-22
189
182
 
190
183
  #### Added