meross-iot 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 (40) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +97 -4
  3. package/index.d.ts +625 -49
  4. package/index.js +25 -17
  5. package/lib/controller/device.js +56 -35
  6. package/lib/controller/features/config-feature.js +3 -2
  7. package/lib/controller/features/diffuser-feature.js +4 -3
  8. package/lib/controller/features/dnd-feature.js +4 -4
  9. package/lib/controller/features/encryption-feature.js +6 -6
  10. package/lib/controller/features/garage-feature.js +2 -1
  11. package/lib/controller/features/light-feature.js +2 -1
  12. package/lib/controller/features/roller-shutter-feature.js +3 -2
  13. package/lib/controller/features/runtime-feature.js +2 -2
  14. package/lib/controller/features/spray-feature.js +2 -1
  15. package/lib/controller/features/thermostat-feature.js +16 -18
  16. package/lib/controller/features/timer-feature.js +11 -10
  17. package/lib/controller/features/toggle-feature.js +4 -4
  18. package/lib/controller/features/trigger-feature.js +11 -10
  19. package/lib/controller/hub-device.js +3 -3
  20. package/lib/controller/subdevice.js +7 -9
  21. package/lib/device-registry.js +332 -0
  22. package/lib/http-api.js +28 -35
  23. package/lib/manager.js +255 -1334
  24. package/lib/managers/devices.js +1092 -0
  25. package/lib/managers/http.js +322 -0
  26. package/lib/managers/mqtt.js +498 -0
  27. package/lib/managers/statistics.js +158 -0
  28. package/lib/{subscription.js → managers/subscription.js} +4 -3
  29. package/lib/managers/transport.js +217 -0
  30. package/lib/model/exception.js +483 -60
  31. package/lib/model/http/device.js +2 -1
  32. package/lib/model/http/exception.js +90 -37
  33. package/lib/model/http/subdevice.js +3 -1
  34. package/lib/utilities/conversion.js +2 -2
  35. package/lib/utilities/debug.js +6 -18
  36. package/lib/utilities/options.js +4 -2
  37. package/lib/utilities/request-queue.js +3 -1
  38. package/lib/utilities/timer.js +13 -8
  39. package/lib/utilities/trigger.js +9 -6
  40. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@ 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.5.0] - 2026-01-19
9
+
10
+ ### Changed
11
+ - **BREAKING**: Standardized error handling with MerossError* naming convention
12
+ - Renamed all error classes to use `MerossError*` prefix for consistency
13
+ - `AuthenticationError` → `MerossErrorAuthentication`
14
+ - `ConnectionError` → `MerossErrorConnection`
15
+ - `DeviceError` → `MerossErrorDevice`
16
+ - `HttpError` → `MerossErrorHttp`
17
+ - `MqttError` → `MerossErrorMqtt`
18
+ - `NetworkError` → `MerossErrorNetwork`
19
+ - `ProtocolError` → `MerossErrorProtocol`
20
+ - `TimeoutError` → `MerossErrorTimeout`
21
+ - `TokenError` → `MerossErrorToken`
22
+ - `ValidationError` → `MerossErrorValidation`
23
+ - All error classes now include `code`, `isOperational`, and `cause` properties
24
+ - Added `toJSON()` method to all error classes for serialization
25
+ - Updated TypeScript definitions to match new error structure
26
+ - Updated error-handling example to use new error class names
27
+ - **BREAKING**: Split ManagerMeross into separate lazy-loaded manager modules
28
+ - Manager methods are now accessed via manager properties instead of direct methods:
29
+ - `manager.devices` - device discovery and initialization (ManagerDevices)
30
+ - `manager.mqtt` - MQTT connection management (ManagerMqtt)
31
+ - `manager.http` - LAN HTTP communication (ManagerHttp)
32
+ - `manager.transport` - transport mode selection and routing (ManagerTransport)
33
+ - `manager.statistics` - statistics tracking (ManagerStatistics)
34
+ - `manager.subscription` - device update subscriptions (ManagerSubscription)
35
+ - Extracted DeviceRegistry to standalone module
36
+ - Moved subscription manager to `managers/` directory
37
+ - Updated all examples and TypeScript definitions for new API
38
+
39
+ ### Added
40
+ - Enhanced error context through error chaining via `cause` property
41
+ - Error serialization support via `toJSON()` method on all error classes
42
+ - Lazy-loaded manager modules for better code organization and performance
43
+
8
44
  ## [0.4.0] - 2026-01-16
9
45
 
10
46
  ### Changed
package/README.md CHANGED
@@ -26,7 +26,7 @@ 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.4.0
29
+ npm install meross-iot@0.5.0
30
30
  ```
31
31
 
32
32
  ## Usage & Documentation
@@ -84,6 +84,63 @@ The `example/` directory contains focused examples for different use cases:
84
84
  - **`multiple-accounts.js`** - Using multiple Meross accounts simultaneously
85
85
  - **`factory-pattern-usage.js`** - Recommended factory pattern for creating HTTP clients and managers
86
86
  - **`timer-usage.js`** - Creating and managing device timers
87
+ - **`selective-initialization.js`** - Selectively initializing devices and subdevices
88
+
89
+ ## Adding and Removing Devices
90
+
91
+ You can dynamically add and remove devices from the manager after initialization:
92
+
93
+ ```javascript
94
+ // Add a single device
95
+ const device = await manager.devices.initializeDevice('device-uuid');
96
+
97
+ // 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'
101
+ });
102
+
103
+ // Remove a device
104
+ const removed = await manager.devices.remove('device-uuid');
105
+
106
+ // Remove a subdevice
107
+ const removed = await manager.devices.remove({
108
+ hubUuid: 'hub-uuid',
109
+ id: 'subdevice-id'
110
+ });
111
+ ```
112
+
113
+ When removing a hub device, all its subdevices are automatically removed as well.
114
+
115
+ ## API Organization
116
+
117
+ The library follows a modular architecture with specialized managers for different concerns:
118
+
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
124
+
125
+ This organization makes the API more discoverable and easier to use. For example:
126
+
127
+ ```javascript
128
+ // Discover devices without initializing
129
+ const availableDevices = await manager.devices.discover({ onlineOnly: true });
130
+
131
+ // Initialize devices
132
+ const count = await manager.devices.initialize();
133
+
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);
137
+
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);
143
+ ```
87
144
 
88
145
  ## Supported Devices
89
146
 
@@ -120,6 +177,45 @@ Please create an issue on GitHub and include:
120
177
 
121
178
  ## Changelog
122
179
 
180
+ ### [0.5.0] - 2026-01-19
181
+
182
+ #### Changed
183
+ - **BREAKING**: Standardized error handling with MerossError* naming convention
184
+ - Renamed all error classes to use `MerossError*` prefix for consistency
185
+ - `AuthenticationError` → `MerossErrorAuthentication`
186
+ - `ConnectionError` → `MerossErrorConnection`
187
+ - `DeviceError` → `MerossErrorDevice`
188
+ - `HttpError` → `MerossErrorHttp`
189
+ - `MqttError` → `MerossErrorMqtt`
190
+ - `NetworkError` → `MerossErrorNetwork`
191
+ - `ProtocolError` → `MerossErrorProtocol`
192
+ - `TimeoutError` → `MerossErrorTimeout`
193
+ - `TokenError` → `MerossErrorToken`
194
+ - `ValidationError` → `MerossErrorValidation`
195
+ - All error classes now include `code`, `isOperational`, and `cause` properties
196
+ - Added `toJSON()` method to all error classes for serialization
197
+ - Updated TypeScript definitions to match new error structure
198
+ - Updated error-handling example to use new error class names
199
+ - **BREAKING**: Split ManagerMeross into separate lazy-loaded manager modules
200
+ - Manager methods are now accessed via manager properties instead of direct methods:
201
+ - `manager.devices` - device discovery and initialization (ManagerDevices)
202
+ - `manager.mqtt` - MQTT connection management (ManagerMqtt)
203
+ - `manager.http` - LAN HTTP communication (ManagerHttp)
204
+ - `manager.transport` - transport mode selection and routing (ManagerTransport)
205
+ - `manager.statistics` - statistics tracking (ManagerStatistics)
206
+ - `manager.subscription` - device update subscriptions (ManagerSubscription)
207
+ - Extracted DeviceRegistry to standalone module
208
+ - Moved subscription manager to `managers/` directory
209
+ - Updated all examples and TypeScript definitions for new API
210
+
211
+ #### Added
212
+ - Enhanced error context through error chaining via `cause` property
213
+ - Error serialization support via `toJSON()` method on all error classes
214
+ - Lazy-loaded manager modules for better code organization and performance
215
+
216
+ <details>
217
+ <summary>Older</summary>
218
+
123
219
  ### [0.4.0] - 2026-01-16
124
220
 
125
221
  #### Changed
@@ -145,9 +241,6 @@ Please create an issue on GitHub and include:
145
241
  - Updated all examples to use camelCase consistently
146
242
  - Updated all examples to use `initializeDevices()` instead of `getDevices()`
147
243
 
148
- <details>
149
- <summary>Older</summary>
150
-
151
244
  ### [0.3.1] - 2026-01-15
152
245
 
153
246
  #### Fixed