meross-iot 0.1.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.
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/index.d.ts +2344 -0
- package/index.js +131 -0
- package/lib/controller/device.js +1317 -0
- package/lib/controller/features/alarm-feature.js +89 -0
- package/lib/controller/features/child-lock-feature.js +61 -0
- package/lib/controller/features/config-feature.js +54 -0
- package/lib/controller/features/consumption-feature.js +210 -0
- package/lib/controller/features/control-feature.js +62 -0
- package/lib/controller/features/diffuser-feature.js +411 -0
- package/lib/controller/features/digest-timer-feature.js +22 -0
- package/lib/controller/features/digest-trigger-feature.js +22 -0
- package/lib/controller/features/dnd-feature.js +79 -0
- package/lib/controller/features/electricity-feature.js +144 -0
- package/lib/controller/features/encryption-feature.js +259 -0
- package/lib/controller/features/garage-feature.js +337 -0
- package/lib/controller/features/hub-feature.js +687 -0
- package/lib/controller/features/light-feature.js +408 -0
- package/lib/controller/features/presence-sensor-feature.js +297 -0
- package/lib/controller/features/roller-shutter-feature.js +456 -0
- package/lib/controller/features/runtime-feature.js +74 -0
- package/lib/controller/features/screen-feature.js +67 -0
- package/lib/controller/features/sensor-history-feature.js +47 -0
- package/lib/controller/features/smoke-config-feature.js +50 -0
- package/lib/controller/features/spray-feature.js +166 -0
- package/lib/controller/features/system-feature.js +269 -0
- package/lib/controller/features/temp-unit-feature.js +55 -0
- package/lib/controller/features/thermostat-feature.js +804 -0
- package/lib/controller/features/timer-feature.js +507 -0
- package/lib/controller/features/toggle-feature.js +223 -0
- package/lib/controller/features/trigger-feature.js +333 -0
- package/lib/controller/hub-device.js +185 -0
- package/lib/controller/subdevice.js +1537 -0
- package/lib/device-factory.js +463 -0
- package/lib/error-budget.js +138 -0
- package/lib/http-api.js +766 -0
- package/lib/manager.js +1609 -0
- package/lib/model/channel-info.js +79 -0
- package/lib/model/constants.js +119 -0
- package/lib/model/enums.js +819 -0
- package/lib/model/exception.js +363 -0
- package/lib/model/http/device.js +215 -0
- package/lib/model/http/error-codes.js +121 -0
- package/lib/model/http/exception.js +151 -0
- package/lib/model/http/subdevice.js +133 -0
- package/lib/model/push/alarm.js +112 -0
- package/lib/model/push/bind.js +97 -0
- package/lib/model/push/common.js +282 -0
- package/lib/model/push/diffuser-light.js +100 -0
- package/lib/model/push/diffuser-spray.js +83 -0
- package/lib/model/push/factory.js +229 -0
- package/lib/model/push/generic.js +115 -0
- package/lib/model/push/hub-battery.js +59 -0
- package/lib/model/push/hub-mts100-all.js +64 -0
- package/lib/model/push/hub-mts100-mode.js +59 -0
- package/lib/model/push/hub-mts100-temperature.js +62 -0
- package/lib/model/push/hub-online.js +59 -0
- package/lib/model/push/hub-sensor-alert.js +61 -0
- package/lib/model/push/hub-sensor-all.js +59 -0
- package/lib/model/push/hub-sensor-smoke.js +110 -0
- package/lib/model/push/hub-sensor-temphum.js +62 -0
- package/lib/model/push/hub-subdevicelist.js +50 -0
- package/lib/model/push/hub-togglex.js +60 -0
- package/lib/model/push/index.js +81 -0
- package/lib/model/push/online.js +53 -0
- package/lib/model/push/presence-study.js +61 -0
- package/lib/model/push/sensor-latestx.js +106 -0
- package/lib/model/push/timerx.js +63 -0
- package/lib/model/push/togglex.js +78 -0
- package/lib/model/push/triggerx.js +62 -0
- package/lib/model/push/unbind.js +34 -0
- package/lib/model/push/water-leak.js +107 -0
- package/lib/model/states/diffuser-light-state.js +119 -0
- package/lib/model/states/diffuser-spray-state.js +58 -0
- package/lib/model/states/garage-door-state.js +71 -0
- package/lib/model/states/index.js +38 -0
- package/lib/model/states/light-state.js +134 -0
- package/lib/model/states/presence-sensor-state.js +239 -0
- package/lib/model/states/roller-shutter-state.js +82 -0
- package/lib/model/states/spray-state.js +58 -0
- package/lib/model/states/thermostat-state.js +297 -0
- package/lib/model/states/timer-state.js +192 -0
- package/lib/model/states/toggle-state.js +105 -0
- package/lib/model/states/trigger-state.js +155 -0
- package/lib/subscription.js +587 -0
- package/lib/utilities/conversion.js +62 -0
- package/lib/utilities/debug.js +165 -0
- package/lib/utilities/mqtt.js +152 -0
- package/lib/utilities/network.js +53 -0
- package/lib/utilities/options.js +64 -0
- package/lib/utilities/request-queue.js +161 -0
- package/lib/utilities/ssid.js +37 -0
- package/lib/utilities/state-changes.js +66 -0
- package/lib/utilities/stats.js +687 -0
- package/lib/utilities/timer.js +310 -0
- package/lib/utilities/trigger.js +286 -0
- package/package.json +73 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,2344 @@
|
|
|
1
|
+
declare module 'meross-iot' {
|
|
2
|
+
import { EventEmitter } from 'events'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Logger function type for debug output.
|
|
6
|
+
*
|
|
7
|
+
* @param message - The log message
|
|
8
|
+
* @param args - Additional arguments to log
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const logger: Logger = (msg, ...args) => console.log(`[Meross] ${msg}`, ...args);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type Logger = (message: string, ...args: any[]) => void
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Channel data structure from device definitions.
|
|
19
|
+
*
|
|
20
|
+
* Represents channel information parsed from device initialization data.
|
|
21
|
+
* Devices can have multiple channels (e.g., master channel at index 0, sub-channels at 1-n).
|
|
22
|
+
*/
|
|
23
|
+
export interface ChannelData {
|
|
24
|
+
/** Channel index (0 for master channel, 1-n for sub-channels) */
|
|
25
|
+
channel?: number
|
|
26
|
+
/** Channel name */
|
|
27
|
+
deviceName?: string
|
|
28
|
+
/** Whether this is the master channel */
|
|
29
|
+
master?: number
|
|
30
|
+
[key: string]: any
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Device definition structure from the Meross API.
|
|
35
|
+
*
|
|
36
|
+
* Contains all device metadata returned from the HTTP API when fetching device lists.
|
|
37
|
+
* This is the raw device information used to initialize MerossDevice instances.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const devices = await httpClient.getDevices();
|
|
42
|
+
* const deviceDef = devices[0]; // DeviceDefinition
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface DeviceDefinition {
|
|
46
|
+
/** Unique device identifier */
|
|
47
|
+
uuid: string
|
|
48
|
+
/** Online status (0=connecting, 1=online, 2=offline, -1=unknown, 3=upgrading) */
|
|
49
|
+
onlineStatus: number
|
|
50
|
+
/** Device name */
|
|
51
|
+
devName: string
|
|
52
|
+
/** Device icon ID */
|
|
53
|
+
devIconId: string
|
|
54
|
+
/** Device bind time (Unix timestamp) */
|
|
55
|
+
bindTime: number
|
|
56
|
+
/** Device type identifier */
|
|
57
|
+
deviceType: string
|
|
58
|
+
/** Device subtype */
|
|
59
|
+
subType: string
|
|
60
|
+
/** Array of channel information */
|
|
61
|
+
channels: ChannelData[]
|
|
62
|
+
/** Device region */
|
|
63
|
+
region: string
|
|
64
|
+
/** Firmware version */
|
|
65
|
+
fmwareVersion: string
|
|
66
|
+
/** Hardware version */
|
|
67
|
+
hdwareVersion: string
|
|
68
|
+
/** User-defined device icon */
|
|
69
|
+
userDevIcon: string
|
|
70
|
+
/** Icon type */
|
|
71
|
+
iconType: number
|
|
72
|
+
/** Skill number */
|
|
73
|
+
skillNumber: string
|
|
74
|
+
/** API domain */
|
|
75
|
+
domain: string
|
|
76
|
+
/** Reserved domain */
|
|
77
|
+
reservedDomain: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Channel metadata for a device.
|
|
82
|
+
*
|
|
83
|
+
* Encapsulates channel information parsed from device initialization data.
|
|
84
|
+
* Devices can have multiple channels (e.g., master channel at index 0, sub-channels at 1-n),
|
|
85
|
+
* each representing a separate control point or feature.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const channels = device.channels;
|
|
90
|
+
* channels.forEach(channel => {
|
|
91
|
+
* console.log(`Channel ${channel.index}: ${channel.name} (USB: ${channel.isUsb})`);
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export class ChannelInfo {
|
|
96
|
+
/** Channel index (0 for master channel, 1-n for sub-channels) */
|
|
97
|
+
readonly index: number
|
|
98
|
+
/** Channel name or null if not set */
|
|
99
|
+
readonly name: string | null
|
|
100
|
+
/** Whether this channel is a USB channel */
|
|
101
|
+
readonly isUsb: boolean
|
|
102
|
+
/** Whether this is the master channel */
|
|
103
|
+
readonly isMasterChannel: boolean
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new ChannelInfo instance.
|
|
107
|
+
*
|
|
108
|
+
* @param index - Channel index (0 for master channel, 1-n for sub-channels)
|
|
109
|
+
* @param name - Channel name (defaults to 'Main channel' for index 0)
|
|
110
|
+
* @param channelType - Channel type (e.g., 'USB')
|
|
111
|
+
* @param isMasterChannel - Whether this is the master channel
|
|
112
|
+
*/
|
|
113
|
+
constructor(index: number, name?: string | null, channelType?: string | null, isMasterChannel?: boolean)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* HTTP API device information.
|
|
118
|
+
*
|
|
119
|
+
* Represents device information retrieved from the Meross HTTP API.
|
|
120
|
+
* This class normalizes device data from the API and provides convenient accessors.
|
|
121
|
+
* Instances are created using the static `fromDict` factory method.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const devices = await httpClient.getDevices();
|
|
126
|
+
* const deviceInfo = HttpDeviceInfo.fromDict(devices[0]);
|
|
127
|
+
* const mqttHost = deviceInfo.getMqttHost();
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export class HttpDeviceInfo {
|
|
131
|
+
/** Unique device identifier */
|
|
132
|
+
readonly uuid: string
|
|
133
|
+
/** Device name */
|
|
134
|
+
readonly devName: string
|
|
135
|
+
/** Device type identifier */
|
|
136
|
+
readonly deviceType: string
|
|
137
|
+
/** Array of channel information */
|
|
138
|
+
readonly channels: ChannelData[]
|
|
139
|
+
/** Firmware version */
|
|
140
|
+
readonly fmwareVersion: string
|
|
141
|
+
/** Hardware version */
|
|
142
|
+
readonly hdwareVersion: string
|
|
143
|
+
/** API domain */
|
|
144
|
+
readonly domain: string
|
|
145
|
+
/** Reserved domain or null */
|
|
146
|
+
readonly reservedDomain: string | null
|
|
147
|
+
/** Device subtype or null */
|
|
148
|
+
readonly subType: string | null
|
|
149
|
+
/** Device bind time as Date or null */
|
|
150
|
+
readonly bindTime: Date | null
|
|
151
|
+
/** Skill number or null */
|
|
152
|
+
readonly skillNumber: string | null
|
|
153
|
+
/** User-defined device icon or null */
|
|
154
|
+
readonly userDevIcon: string | null
|
|
155
|
+
/** Icon type or null */
|
|
156
|
+
readonly iconType: number | null
|
|
157
|
+
/** Device region or null */
|
|
158
|
+
readonly region: string | null
|
|
159
|
+
/** Device icon ID or null */
|
|
160
|
+
readonly devIconId: string | null
|
|
161
|
+
/** Online status (0=connecting, 1=online, 2=offline, -1=unknown, 3=upgrading) */
|
|
162
|
+
readonly onlineStatus: number
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Creates an HttpDeviceInfo instance from a dictionary object.
|
|
166
|
+
*
|
|
167
|
+
* Normalizes incoming keys (handles camelCase and snake_case) to camelCase.
|
|
168
|
+
* This is the only way to create instances.
|
|
169
|
+
*
|
|
170
|
+
* @param jsonDict - Dictionary object from the API response
|
|
171
|
+
* @returns New HttpDeviceInfo instance
|
|
172
|
+
*/
|
|
173
|
+
static fromDict(jsonDict: { [key: string]: any }): HttpDeviceInfo
|
|
174
|
+
|
|
175
|
+
/** @private */
|
|
176
|
+
private constructor()
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Converts the instance to a plain object dictionary with camelCase keys.
|
|
180
|
+
*
|
|
181
|
+
* @returns Plain object with camelCase keys
|
|
182
|
+
*/
|
|
183
|
+
toDict(): {
|
|
184
|
+
uuid: string
|
|
185
|
+
devName: string
|
|
186
|
+
deviceType: string
|
|
187
|
+
channels: ChannelData[]
|
|
188
|
+
fmwareVersion: string
|
|
189
|
+
hdwareVersion: string
|
|
190
|
+
domain: string
|
|
191
|
+
reservedDomain: string | null
|
|
192
|
+
subType: string | null
|
|
193
|
+
bindTime: Date | null
|
|
194
|
+
skillNumber: string | null
|
|
195
|
+
userDevIcon: string | null
|
|
196
|
+
iconType: number | null
|
|
197
|
+
region: string | null
|
|
198
|
+
devIconId: string | null
|
|
199
|
+
onlineStatus: number
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Gets the MQTT host for this device.
|
|
204
|
+
*
|
|
205
|
+
* @returns MQTT broker hostname
|
|
206
|
+
*/
|
|
207
|
+
getMqttHost(): string
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Gets the MQTT port for this device.
|
|
211
|
+
*
|
|
212
|
+
* @returns MQTT broker port number
|
|
213
|
+
*/
|
|
214
|
+
getMqttPort(): number
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export class HttpSubdeviceInfo {
|
|
218
|
+
readonly subDeviceId: string | null
|
|
219
|
+
readonly trueId: string | null
|
|
220
|
+
readonly subDeviceType: string | null
|
|
221
|
+
readonly subDeviceVendor: string | null
|
|
222
|
+
readonly subDeviceName: string | null
|
|
223
|
+
readonly subDeviceIconId: string | null
|
|
224
|
+
/**
|
|
225
|
+
* Creates an HttpSubdeviceInfo instance from a dictionary object.
|
|
226
|
+
* Normalizes incoming keys (handles camelCase, snake_case, and generic keys) to camelCase.
|
|
227
|
+
* This is the only way to create instances.
|
|
228
|
+
*/
|
|
229
|
+
static fromDict(jsonDict: { [key: string]: any }): HttpSubdeviceInfo
|
|
230
|
+
private constructor()
|
|
231
|
+
/**
|
|
232
|
+
* Converts the instance to a plain object dictionary with camelCase keys.
|
|
233
|
+
*/
|
|
234
|
+
toDict(): {
|
|
235
|
+
subDeviceId: string | null
|
|
236
|
+
trueId: string | null
|
|
237
|
+
subDeviceType: string | null
|
|
238
|
+
subDeviceVendor: string | null
|
|
239
|
+
subDeviceName: string | null
|
|
240
|
+
subDeviceIconId: string | null
|
|
241
|
+
}
|
|
242
|
+
toString(): string
|
|
243
|
+
toJSON(): string
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export class HardwareInfo {
|
|
247
|
+
readonly version: string | null
|
|
248
|
+
readonly uuid: string | null
|
|
249
|
+
readonly type: string | null
|
|
250
|
+
readonly subType: string | null
|
|
251
|
+
readonly macAddress: string | null
|
|
252
|
+
readonly chipType: string | null
|
|
253
|
+
/**
|
|
254
|
+
* Creates a HardwareInfo instance from a dictionary object.
|
|
255
|
+
* Normalizes incoming keys (handles camelCase and snake_case) to camelCase.
|
|
256
|
+
* This is the only way to create instances.
|
|
257
|
+
*/
|
|
258
|
+
static fromDict(jsonDict: { [key: string]: any }): HardwareInfo | null
|
|
259
|
+
private constructor()
|
|
260
|
+
/**
|
|
261
|
+
* Converts the instance to a plain object dictionary with camelCase keys.
|
|
262
|
+
*/
|
|
263
|
+
toDict(): {
|
|
264
|
+
version: string | null
|
|
265
|
+
uuid: string | null
|
|
266
|
+
type: string | null
|
|
267
|
+
subType: string | null
|
|
268
|
+
macAddress: string | null
|
|
269
|
+
chipType: string | null
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export class FirmwareInfo {
|
|
274
|
+
readonly wifiMac: string | null
|
|
275
|
+
readonly version: string | null
|
|
276
|
+
readonly userId: string | null
|
|
277
|
+
readonly server: string | null
|
|
278
|
+
readonly port: number | null
|
|
279
|
+
readonly innerIp: string | null
|
|
280
|
+
readonly compileTime: string | null
|
|
281
|
+
/**
|
|
282
|
+
* Creates a FirmwareInfo instance from a dictionary object.
|
|
283
|
+
* Normalizes incoming keys (handles camelCase and snake_case) to camelCase.
|
|
284
|
+
* This is the only way to create instances.
|
|
285
|
+
*/
|
|
286
|
+
static fromDict(jsonDict: { [key: string]: any }): FirmwareInfo | null
|
|
287
|
+
private constructor()
|
|
288
|
+
/**
|
|
289
|
+
* Converts the instance to a plain object dictionary with camelCase keys.
|
|
290
|
+
*/
|
|
291
|
+
toDict(): {
|
|
292
|
+
wifiMac: string | null
|
|
293
|
+
version: string | null
|
|
294
|
+
userId: string | null
|
|
295
|
+
server: string | null
|
|
296
|
+
port: number | null
|
|
297
|
+
innerIp: string | null
|
|
298
|
+
compileTime: string | null
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export class TimeInfo {
|
|
303
|
+
readonly timezone: string | null
|
|
304
|
+
readonly timestamp: number | null
|
|
305
|
+
readonly timeRule: string | null
|
|
306
|
+
/**
|
|
307
|
+
* Creates a TimeInfo instance from a dictionary object.
|
|
308
|
+
* Normalizes incoming keys (handles camelCase and snake_case) to camelCase.
|
|
309
|
+
* This is the only way to create instances.
|
|
310
|
+
*/
|
|
311
|
+
static fromDict(jsonDict: { [key: string]: any }): TimeInfo | null
|
|
312
|
+
private constructor()
|
|
313
|
+
/**
|
|
314
|
+
* Converts the instance to a plain object dictionary with camelCase keys.
|
|
315
|
+
*/
|
|
316
|
+
toDict(): {
|
|
317
|
+
timezone: string | null
|
|
318
|
+
timestamp: number | null
|
|
319
|
+
timeRule: string | null
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export interface GetControlPowerConsumptionXResponse {
|
|
324
|
+
consumptionx: {
|
|
325
|
+
date: string
|
|
326
|
+
/**
|
|
327
|
+
* timestamp, utc.
|
|
328
|
+
* has to be multiplied by 1000 to use on new Date(time)
|
|
329
|
+
*/
|
|
330
|
+
time: number
|
|
331
|
+
value: number
|
|
332
|
+
}[]
|
|
333
|
+
}
|
|
334
|
+
export interface GetControlElectricityResponse {
|
|
335
|
+
electricity: {
|
|
336
|
+
channel: number
|
|
337
|
+
/**
|
|
338
|
+
* current in decimilliAmp. Has to get divided by 10000 to get Amp(s)
|
|
339
|
+
*/
|
|
340
|
+
current: number
|
|
341
|
+
/**
|
|
342
|
+
* voltage in deciVolt. Has to get divided by 10 to get Volt(s)
|
|
343
|
+
*/
|
|
344
|
+
voltage: number
|
|
345
|
+
/**
|
|
346
|
+
* power in milliWatt. Has to get divided by 1000 to get Watt(s)
|
|
347
|
+
*/
|
|
348
|
+
power: number
|
|
349
|
+
config: {
|
|
350
|
+
voltageRatio: number
|
|
351
|
+
electricityRatio: number
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Authentication token data.
|
|
358
|
+
*
|
|
359
|
+
* Contains all information needed to authenticate with the Meross API.
|
|
360
|
+
* Can be saved and reused with MerossHttpClient.fromCredentials().
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const tokenData = manager.getTokenData();
|
|
365
|
+
* // Save tokenData for later use
|
|
366
|
+
* const httpClient = MerossHttpClient.fromCredentials({
|
|
367
|
+
* token: tokenData.token,
|
|
368
|
+
* key: tokenData.key,
|
|
369
|
+
* userId: tokenData.userId,
|
|
370
|
+
* domain: tokenData.domain,
|
|
371
|
+
* mqttDomain: tokenData.mqttDomain
|
|
372
|
+
* });
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
export interface TokenData {
|
|
376
|
+
/** Authentication token */
|
|
377
|
+
token: string;
|
|
378
|
+
/** Encryption key */
|
|
379
|
+
key: string;
|
|
380
|
+
/** User ID */
|
|
381
|
+
userId: string;
|
|
382
|
+
/** Hash value */
|
|
383
|
+
hash: string;
|
|
384
|
+
/** API domain */
|
|
385
|
+
domain: string;
|
|
386
|
+
/** MQTT domain */
|
|
387
|
+
mqttDomain: string;
|
|
388
|
+
/** Token issue timestamp (optional) */
|
|
389
|
+
issued_on?: string;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Transport mode for device communication.
|
|
394
|
+
*
|
|
395
|
+
* Determines how the library communicates with Meross devices. Each mode
|
|
396
|
+
* uses different protocols and network paths, affecting latency, reliability,
|
|
397
|
+
* and whether remote access is required.
|
|
398
|
+
*/
|
|
399
|
+
export enum TransportMode {
|
|
400
|
+
/** MQTT-only communication through Meross cloud broker */
|
|
401
|
+
MQTT_ONLY = 0,
|
|
402
|
+
/** LAN HTTP with MQTT fallback - attempts direct HTTP first, falls back to MQTT */
|
|
403
|
+
LAN_HTTP_FIRST = 1,
|
|
404
|
+
/** LAN HTTP for reads only, MQTT for writes - uses LAN for GET requests, MQTT for SET */
|
|
405
|
+
LAN_HTTP_FIRST_ONLY_GET = 2
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export const OnlineStatus: {
|
|
409
|
+
NOT_ONLINE: 0;
|
|
410
|
+
ONLINE: 1;
|
|
411
|
+
OFFLINE: 2;
|
|
412
|
+
UNKNOWN: -1;
|
|
413
|
+
UPGRADING: 3;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export const DNDMode: {
|
|
417
|
+
DND_DISABLED: 0;
|
|
418
|
+
DND_ENABLED: 1;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export const PresenceState: {
|
|
422
|
+
ABSENCE: 1;
|
|
423
|
+
PRESENCE: 2;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export const SensitivityLevel: {
|
|
427
|
+
RESPONSIVE: 0;
|
|
428
|
+
ANTI_INTERFERENCE: 1;
|
|
429
|
+
BALANCE: 2;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export const WorkMode: {
|
|
433
|
+
UNKNOWN: 0;
|
|
434
|
+
BIOLOGICAL_DETECTION_ONLY: 1;
|
|
435
|
+
SECURITY: 2;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Configuration options for MerossManager cloud manager.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* const httpClient = await MerossHttpClient.fromUserPassword({
|
|
444
|
+
* email: 'user@example.com',
|
|
445
|
+
* password: 'password'
|
|
446
|
+
* });
|
|
447
|
+
*
|
|
448
|
+
* const manager = new MerossManager({
|
|
449
|
+
* httpClient,
|
|
450
|
+
* transportMode: TransportMode.LAN_HTTP_FIRST,
|
|
451
|
+
* logger: console.log
|
|
452
|
+
* });
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
export interface CloudOptions {
|
|
456
|
+
/** HTTP client instance (required - use MerossHttpClient.fromUserPassword()) */
|
|
457
|
+
httpClient: MerossHttpClient;
|
|
458
|
+
/** Logger function for debug output */
|
|
459
|
+
logger?: Logger;
|
|
460
|
+
/** Transport mode for device communication */
|
|
461
|
+
transportMode?: TransportMode;
|
|
462
|
+
/** Request timeout in milliseconds */
|
|
463
|
+
timeout?: number,
|
|
464
|
+
/** Automatically retry on bad domain errors */
|
|
465
|
+
autoRetryOnBadDomain?: boolean,
|
|
466
|
+
/** Maximum errors allowed per device before skipping LAN HTTP (default: 1) */
|
|
467
|
+
maxErrors?: number,
|
|
468
|
+
/** Time window in milliseconds for error budget (default: 60000) */
|
|
469
|
+
errorBudgetTimeWindow?: number,
|
|
470
|
+
/** Enable statistics tracking (default: false) */
|
|
471
|
+
enableStats?: boolean,
|
|
472
|
+
/** Maximum number of samples to keep in statistics (default: 1000) */
|
|
473
|
+
maxStatsSamples?: number,
|
|
474
|
+
/** Number of concurrent requests per device (default: 1) */
|
|
475
|
+
requestBatchSize?: number,
|
|
476
|
+
/** Delay in milliseconds between batches (default: 200) */
|
|
477
|
+
requestBatchDelay?: number,
|
|
478
|
+
/** Enable/disable request throttling (default: true) */
|
|
479
|
+
enableRequestThrottling?: boolean
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export interface LightData {
|
|
483
|
+
channel: number;
|
|
484
|
+
capacity: number;
|
|
485
|
+
gradual: number;
|
|
486
|
+
rgb?: number;
|
|
487
|
+
temperature?: number;
|
|
488
|
+
luminance?: number;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export interface ThermostatModeData {
|
|
492
|
+
channel: number;
|
|
493
|
+
heatTemp?: number;
|
|
494
|
+
coolTemp?: number;
|
|
495
|
+
manualTemp?: number;
|
|
496
|
+
ecoTemp?: number;
|
|
497
|
+
targetTemp?: number;
|
|
498
|
+
mode?: number;
|
|
499
|
+
onoff?: number;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export enum ThermostatMode {
|
|
503
|
+
HEAT = 0,
|
|
504
|
+
COOL = 1,
|
|
505
|
+
ECONOMY = 2,
|
|
506
|
+
AUTO = 3,
|
|
507
|
+
MANUAL = 4
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export enum ThermostatWorkingMode {
|
|
511
|
+
HEAT = 1,
|
|
512
|
+
COOL = 2
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export enum ThermostatModeBState {
|
|
516
|
+
HEATING_COOLING = 1,
|
|
517
|
+
NOT_HEATING_COOLING = 2
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* State update data for ThermostatState
|
|
522
|
+
*/
|
|
523
|
+
export interface ThermostatStateUpdate {
|
|
524
|
+
onoff?: number
|
|
525
|
+
channel?: number
|
|
526
|
+
mode?: number
|
|
527
|
+
targetTemp?: number
|
|
528
|
+
currentTemp?: number
|
|
529
|
+
working?: number
|
|
530
|
+
state?: number
|
|
531
|
+
warning?: number
|
|
532
|
+
min?: number
|
|
533
|
+
max?: number
|
|
534
|
+
heatTemp?: number
|
|
535
|
+
coolTemp?: number
|
|
536
|
+
ecoTemp?: number
|
|
537
|
+
manualTemp?: number
|
|
538
|
+
[key: string]: any
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export interface ThermostatState {
|
|
542
|
+
readonly isOn?: boolean;
|
|
543
|
+
readonly mode?: number;
|
|
544
|
+
readonly workingMode?: number;
|
|
545
|
+
readonly state?: number;
|
|
546
|
+
readonly warning?: boolean;
|
|
547
|
+
readonly targetTemperatureCelsius?: number;
|
|
548
|
+
readonly currentTemperatureCelsius?: number;
|
|
549
|
+
readonly minTemperatureCelsius?: number;
|
|
550
|
+
readonly maxTemperatureCelsius?: number;
|
|
551
|
+
readonly heatTemperatureCelsius?: number;
|
|
552
|
+
readonly coolTemperatureCelsius?: number;
|
|
553
|
+
readonly ecoTemperatureCelsius?: number;
|
|
554
|
+
readonly manualTemperatureCelsius?: number;
|
|
555
|
+
update(state: ThermostatStateUpdate): void;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export enum LightMode {
|
|
559
|
+
MODE_RGB = 1,
|
|
560
|
+
MODE_TEMPERATURE = 2,
|
|
561
|
+
MODE_LUMINANCE = 4
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* State update data for LightState
|
|
566
|
+
*/
|
|
567
|
+
export interface LightStateUpdate {
|
|
568
|
+
onoff?: number
|
|
569
|
+
channel?: number
|
|
570
|
+
rgb?: number
|
|
571
|
+
luminance?: number
|
|
572
|
+
temperature?: number
|
|
573
|
+
capacity?: number
|
|
574
|
+
[key: string]: any
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export interface LightState {
|
|
578
|
+
readonly isOn?: boolean;
|
|
579
|
+
readonly rgbTuple?: [number, number, number];
|
|
580
|
+
readonly rgbInt?: number;
|
|
581
|
+
readonly luminance?: number;
|
|
582
|
+
readonly temperature?: number;
|
|
583
|
+
readonly capacity?: number;
|
|
584
|
+
update(state: LightStateUpdate): void;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Options for setting light color and properties.
|
|
589
|
+
*
|
|
590
|
+
* Used with MerossDevice.setLightColor() to control RGB lights.
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```typescript
|
|
594
|
+
* // Set RGB color
|
|
595
|
+
* await device.setLightColor({
|
|
596
|
+
* channel: 0,
|
|
597
|
+
* rgb: [255, 0, 0], // Red
|
|
598
|
+
* luminance: 50,
|
|
599
|
+
* onoff: true
|
|
600
|
+
* });
|
|
601
|
+
*
|
|
602
|
+
* // Set color temperature
|
|
603
|
+
* await device.setLightColor({
|
|
604
|
+
* channel: 0,
|
|
605
|
+
* temperature: 50,
|
|
606
|
+
* luminance: 75
|
|
607
|
+
* });
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
export interface LightColorOptions {
|
|
611
|
+
/** Channel number (default: 0) */
|
|
612
|
+
channel?: number;
|
|
613
|
+
/** Whether to turn the light on */
|
|
614
|
+
onoff?: boolean;
|
|
615
|
+
/** RGB color - can be array [r,g,b], object {r,g,b}, or integer */
|
|
616
|
+
rgb?: [number, number, number] | { r: number; g: number; b: number } | { red: number; green: number; blue: number } | number;
|
|
617
|
+
/** Brightness level (1-100) */
|
|
618
|
+
luminance?: number;
|
|
619
|
+
/** Color temperature (1-100, where 1 is warmest, 100 is coolest) */
|
|
620
|
+
temperature?: number;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export enum DiffuserLightMode {
|
|
624
|
+
ROTATING_COLORS = 0,
|
|
625
|
+
FIXED_RGB = 1,
|
|
626
|
+
FIXED_LUMINANCE = 2
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export enum DiffuserSprayMode {
|
|
630
|
+
LIGHT = 0,
|
|
631
|
+
STRONG = 1,
|
|
632
|
+
OFF = 2
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export enum SprayMode {
|
|
636
|
+
OFF = 0,
|
|
637
|
+
CONTINUOUS = 1,
|
|
638
|
+
INTERMITTENT = 2
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export enum RollerShutterStatus {
|
|
642
|
+
UNKNOWN = -1,
|
|
643
|
+
IDLE = 0,
|
|
644
|
+
OPENING = 1,
|
|
645
|
+
CLOSING = 2
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export enum SmokeAlarmStatus {
|
|
649
|
+
NORMAL = 23,
|
|
650
|
+
MUTE_TEMPERATURE_ALARM = 26,
|
|
651
|
+
MUTE_SMOKE_ALARM = 27,
|
|
652
|
+
INTERCONNECTION_STATUS = 170
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export enum TimerType {
|
|
656
|
+
SINGLE_POINT_WEEKLY_CYCLE = 1,
|
|
657
|
+
SINGLE_POINT_SINGLE_SHOT = 2,
|
|
658
|
+
CONTINUOUS_WEEKLY_CYCLE = 3,
|
|
659
|
+
CONTINUOUS_SINGLE_SHOT = 4,
|
|
660
|
+
AUTO_OFF = 1,
|
|
661
|
+
COUNTDOWN = 2
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export enum TriggerType {
|
|
665
|
+
SINGLE_POINT_WEEKLY_CYCLE = 1,
|
|
666
|
+
SINGLE_POINT_SINGLE_SHOT = 2,
|
|
667
|
+
CONTINUOUS_WEEKLY_CYCLE = 3,
|
|
668
|
+
CONTINUOUS_SINGLE_SHOT = 4
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* State update data for DiffuserLightState
|
|
673
|
+
*/
|
|
674
|
+
export interface DiffuserLightStateUpdate {
|
|
675
|
+
onoff?: number
|
|
676
|
+
channel?: number
|
|
677
|
+
mode?: number
|
|
678
|
+
rgb?: number
|
|
679
|
+
luminance?: number
|
|
680
|
+
[key: string]: any
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export interface DiffuserLightState {
|
|
684
|
+
readonly isOn?: boolean;
|
|
685
|
+
readonly mode?: number;
|
|
686
|
+
readonly rgbTuple?: [number, number, number];
|
|
687
|
+
readonly rgbInt?: number;
|
|
688
|
+
readonly luminance?: number;
|
|
689
|
+
update(state: DiffuserLightStateUpdate): void;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* State update data for DiffuserSprayState
|
|
694
|
+
*/
|
|
695
|
+
export interface DiffuserSprayStateUpdate {
|
|
696
|
+
channel?: number
|
|
697
|
+
mode?: number
|
|
698
|
+
[key: string]: any
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
export interface DiffuserSprayState {
|
|
702
|
+
readonly mode?: number;
|
|
703
|
+
update(state: DiffuserSprayStateUpdate): void;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* State update data for SprayState
|
|
708
|
+
*/
|
|
709
|
+
export interface SprayStateUpdate {
|
|
710
|
+
channel?: number
|
|
711
|
+
mode?: number
|
|
712
|
+
[key: string]: any
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
export interface SprayState {
|
|
716
|
+
readonly mode?: number;
|
|
717
|
+
update(state: SprayStateUpdate): void;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* State update data for RollerShutterState
|
|
722
|
+
*/
|
|
723
|
+
export interface RollerShutterStateUpdate {
|
|
724
|
+
channel?: number
|
|
725
|
+
state?: number
|
|
726
|
+
position?: number
|
|
727
|
+
[key: string]: any
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
export interface RollerShutterState {
|
|
731
|
+
readonly state?: number;
|
|
732
|
+
readonly position?: number;
|
|
733
|
+
readonly channel?: number;
|
|
734
|
+
update(state: RollerShutterStateUpdate): void;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* State update data for GarageDoorState
|
|
739
|
+
*/
|
|
740
|
+
export interface GarageDoorStateUpdate {
|
|
741
|
+
channel?: number
|
|
742
|
+
open?: number
|
|
743
|
+
[key: string]: any
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export interface GarageDoorState {
|
|
747
|
+
readonly isOpen?: boolean;
|
|
748
|
+
readonly channel?: number;
|
|
749
|
+
update(state: GarageDoorStateUpdate): void;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* State update data for TimerState
|
|
754
|
+
*/
|
|
755
|
+
export interface TimerStateUpdate {
|
|
756
|
+
id?: string | number
|
|
757
|
+
channel?: number
|
|
758
|
+
week?: number
|
|
759
|
+
time?: number
|
|
760
|
+
enable?: number | boolean
|
|
761
|
+
alias?: string
|
|
762
|
+
type?: number
|
|
763
|
+
duration?: number
|
|
764
|
+
sunOffset?: number
|
|
765
|
+
createTime?: number
|
|
766
|
+
extend?: Record<string, any>
|
|
767
|
+
[key: string]: any
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
export interface TimerState {
|
|
771
|
+
readonly id?: string | number;
|
|
772
|
+
readonly channel?: number;
|
|
773
|
+
readonly week?: number;
|
|
774
|
+
readonly time?: number;
|
|
775
|
+
readonly enable?: boolean;
|
|
776
|
+
readonly alias?: string;
|
|
777
|
+
readonly type?: number;
|
|
778
|
+
readonly duration?: number;
|
|
779
|
+
readonly sunOffset?: number;
|
|
780
|
+
readonly createTime?: number;
|
|
781
|
+
readonly extend?: Record<string, any>;
|
|
782
|
+
update(state: TimerStateUpdate): void;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* State update data for TriggerState
|
|
787
|
+
*/
|
|
788
|
+
export interface TriggerStateUpdate {
|
|
789
|
+
id?: string | number
|
|
790
|
+
channel?: number
|
|
791
|
+
alias?: string
|
|
792
|
+
enable?: number | boolean
|
|
793
|
+
type?: number
|
|
794
|
+
createTime?: number
|
|
795
|
+
rule?: Record<string, any>
|
|
796
|
+
ruleDuration?: number
|
|
797
|
+
ruleWeek?: number
|
|
798
|
+
[key: string]: any
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
export interface TriggerState {
|
|
802
|
+
readonly id?: string | number;
|
|
803
|
+
readonly channel?: number;
|
|
804
|
+
readonly alias?: string;
|
|
805
|
+
readonly enable?: boolean;
|
|
806
|
+
readonly type?: number;
|
|
807
|
+
readonly createTime?: number;
|
|
808
|
+
readonly rule?: Record<string, any>;
|
|
809
|
+
readonly ruleDuration?: number;
|
|
810
|
+
readonly ruleWeek?: number;
|
|
811
|
+
update(state: TriggerStateUpdate): void;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* State update data for PresenceSensorState
|
|
816
|
+
*/
|
|
817
|
+
export interface PresenceSensorStateUpdate {
|
|
818
|
+
channel?: number
|
|
819
|
+
presence?: Record<string, any>
|
|
820
|
+
light?: Record<string, any>
|
|
821
|
+
[key: string]: any
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
export interface PresenceSensorState {
|
|
825
|
+
readonly isPresent?: boolean;
|
|
826
|
+
readonly presenceValue?: number;
|
|
827
|
+
readonly presenceState?: string;
|
|
828
|
+
readonly distanceMeters?: number;
|
|
829
|
+
readonly distanceRaw?: number;
|
|
830
|
+
readonly presenceTimestamp?: Date;
|
|
831
|
+
readonly presenceTimes?: number;
|
|
832
|
+
readonly lightLux?: number;
|
|
833
|
+
readonly lightTimestamp?: Date;
|
|
834
|
+
readonly channel?: number;
|
|
835
|
+
readonly rawPresence?: Record<string, any>;
|
|
836
|
+
readonly rawLight?: Record<string, any>;
|
|
837
|
+
update(state: PresenceSensorStateUpdate): void;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* State update data for ToggleState
|
|
842
|
+
*/
|
|
843
|
+
export interface ToggleStateUpdate {
|
|
844
|
+
channel?: number
|
|
845
|
+
onoff?: number
|
|
846
|
+
lmTime?: number
|
|
847
|
+
entity?: number
|
|
848
|
+
[key: string]: any
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
export interface ToggleState {
|
|
852
|
+
readonly isOn?: boolean;
|
|
853
|
+
readonly onoff?: number;
|
|
854
|
+
readonly channel?: number;
|
|
855
|
+
readonly lmTime?: number;
|
|
856
|
+
readonly entity?: number;
|
|
857
|
+
update(state: ToggleStateUpdate): void;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export class GenericPushNotification {
|
|
861
|
+
readonly namespace: string;
|
|
862
|
+
readonly originatingDeviceUuid: string;
|
|
863
|
+
readonly rawData: any;
|
|
864
|
+
constructor(namespace: string, originatingDeviceUuid: string, rawData: any);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
export class OnlinePushNotification extends GenericPushNotification {
|
|
868
|
+
readonly status?: number;
|
|
869
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
export class AlarmPushNotification extends GenericPushNotification {
|
|
873
|
+
readonly value?: number | string | Record<string, any>;
|
|
874
|
+
readonly timestamp?: number;
|
|
875
|
+
readonly channel?: number;
|
|
876
|
+
readonly subdevice_id?: string;
|
|
877
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
export class BindPushNotification extends GenericPushNotification {
|
|
881
|
+
readonly time: TimeInfo | null
|
|
882
|
+
readonly hwinfo: HardwareInfo | null
|
|
883
|
+
readonly fwinfo: FirmwareInfo | null
|
|
884
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
export class UnbindPushNotification extends GenericPushNotification {
|
|
888
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
export class WaterLeakPushNotification extends GenericPushNotification {
|
|
892
|
+
readonly syncedTime?: number | Record<string, any>;
|
|
893
|
+
readonly latestSampleTime?: number;
|
|
894
|
+
readonly latestSampleIsLeak?: number;
|
|
895
|
+
readonly subdevice_id?: string;
|
|
896
|
+
readonly samples?: Array<{ time: number; isLeak: number; [key: string]: any }>;
|
|
897
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Hub online data structure
|
|
902
|
+
*/
|
|
903
|
+
export interface HubOnlineData {
|
|
904
|
+
subdeviceId: string
|
|
905
|
+
onlineStatus: number
|
|
906
|
+
[key: string]: any
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Hub toggle data structure
|
|
911
|
+
*/
|
|
912
|
+
export interface HubToggleXData {
|
|
913
|
+
subdeviceId: string
|
|
914
|
+
onoff: number
|
|
915
|
+
[key: string]: any
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Hub battery data structure
|
|
920
|
+
*/
|
|
921
|
+
export interface HubBatteryData {
|
|
922
|
+
subdeviceId: string
|
|
923
|
+
battery: number
|
|
924
|
+
[key: string]: any
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Hub sensor data structure
|
|
929
|
+
*/
|
|
930
|
+
export interface HubSensorData {
|
|
931
|
+
subdeviceId: string
|
|
932
|
+
[key: string]: any
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
export class HubOnlinePushNotification extends GenericPushNotification {
|
|
936
|
+
readonly onlineData: HubOnlineData[];
|
|
937
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
export class HubToggleXPushNotification extends GenericPushNotification {
|
|
941
|
+
readonly togglexData: HubToggleXData[];
|
|
942
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
export class HubBatteryPushNotification extends GenericPushNotification {
|
|
946
|
+
readonly batteryData: HubBatteryData[];
|
|
947
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
export class HubSensorAllPushNotification extends GenericPushNotification {
|
|
951
|
+
readonly allData: HubSensorData[];
|
|
952
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
export class HubSensorTempHumPushNotification extends GenericPushNotification {
|
|
956
|
+
readonly tempHumData: HubSensorData[];
|
|
957
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
export class HubSensorAlertPushNotification extends GenericPushNotification {
|
|
961
|
+
readonly alertData: HubSensorData[];
|
|
962
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
export class HubSensorSmokePushNotification extends GenericPushNotification {
|
|
966
|
+
readonly subdevice_id?: string | number;
|
|
967
|
+
readonly status?: number;
|
|
968
|
+
readonly interConn?: number | Record<string, any>;
|
|
969
|
+
readonly timestamp?: number;
|
|
970
|
+
readonly testEvent?: boolean;
|
|
971
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* MTS100 thermostat data structure
|
|
976
|
+
*/
|
|
977
|
+
export interface HubMts100Data {
|
|
978
|
+
subdeviceId: string
|
|
979
|
+
[key: string]: any
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Subdevice list data structure
|
|
984
|
+
*/
|
|
985
|
+
export interface HubSubdeviceListData {
|
|
986
|
+
subdeviceId: string
|
|
987
|
+
subDeviceType: string
|
|
988
|
+
[key: string]: any
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Timer data structure
|
|
993
|
+
*/
|
|
994
|
+
export interface TimerXData {
|
|
995
|
+
timerId: string
|
|
996
|
+
channel: number
|
|
997
|
+
[key: string]: any
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Trigger data structure
|
|
1002
|
+
*/
|
|
1003
|
+
export interface TriggerXData {
|
|
1004
|
+
triggerId: string
|
|
1005
|
+
channel: number
|
|
1006
|
+
[key: string]: any
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Presence study data structure
|
|
1011
|
+
*/
|
|
1012
|
+
export interface PresenceStudyData {
|
|
1013
|
+
channel: number
|
|
1014
|
+
[key: string]: any
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Sensor latest data structure
|
|
1019
|
+
*/
|
|
1020
|
+
export interface SensorLatestXData {
|
|
1021
|
+
channel: number
|
|
1022
|
+
[key: string]: any
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Diffuser light data structure
|
|
1027
|
+
*/
|
|
1028
|
+
export interface DiffuserLightData {
|
|
1029
|
+
channel: number
|
|
1030
|
+
onoff: number
|
|
1031
|
+
[key: string]: any
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Diffuser spray data structure
|
|
1036
|
+
*/
|
|
1037
|
+
export interface DiffuserSprayData {
|
|
1038
|
+
channel: number
|
|
1039
|
+
mode: number
|
|
1040
|
+
[key: string]: any
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
export class HubMts100AllPushNotification extends GenericPushNotification {
|
|
1044
|
+
readonly allData: HubMts100Data[];
|
|
1045
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
export class HubMts100ModePushNotification extends GenericPushNotification {
|
|
1049
|
+
readonly modeData: HubMts100Data[];
|
|
1050
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
export class HubMts100TemperaturePushNotification extends GenericPushNotification {
|
|
1054
|
+
readonly temperatureData: HubMts100Data[];
|
|
1055
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
export class HubSubdeviceListPushNotification extends GenericPushNotification {
|
|
1059
|
+
readonly subdeviceListData: HubSubdeviceListData[];
|
|
1060
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
export class TimerXPushNotification extends GenericPushNotification {
|
|
1064
|
+
readonly timerxData: TimerXData[];
|
|
1065
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export class TriggerXPushNotification extends GenericPushNotification {
|
|
1069
|
+
readonly triggerxData: TriggerXData[];
|
|
1070
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
export class PresenceStudyPushNotification extends GenericPushNotification {
|
|
1074
|
+
readonly studyData: PresenceStudyData[];
|
|
1075
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
export class ToggleXPushNotification extends GenericPushNotification {
|
|
1079
|
+
readonly togglexData: HubToggleXData[];
|
|
1080
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
export class SensorLatestXPushNotification extends GenericPushNotification {
|
|
1084
|
+
readonly latestData: SensorLatestXData[];
|
|
1085
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export class DiffuserLightPushNotification extends GenericPushNotification {
|
|
1089
|
+
readonly lightData: DiffuserLightData[];
|
|
1090
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
export class DiffuserSprayPushNotification extends GenericPushNotification {
|
|
1094
|
+
readonly sprayData: DiffuserSprayData[];
|
|
1095
|
+
constructor(originatingDeviceUuid: string, rawData: any);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
export function parsePushNotification(namespace: string, messagePayload: any, deviceUuid: string): GenericPushNotification | null;
|
|
1099
|
+
|
|
1100
|
+
export type MessageId = string
|
|
1101
|
+
/** @deprecated Use Promise-based methods instead */
|
|
1102
|
+
export type Callback<T> = (error: Error | null, data: T) => void
|
|
1103
|
+
/** @deprecated Use Promise-based methods instead */
|
|
1104
|
+
export type ErrorCallback = (error: Error | null) => void
|
|
1105
|
+
export type DeviceInitializedEvent = 'deviceInitialized'
|
|
1106
|
+
|
|
1107
|
+
export type DeviceInitializedCallback = (deviceId: string, deviceDef: DeviceDefinition, device: MerossDevice) => void
|
|
1108
|
+
|
|
1109
|
+
export type PushNotificationEvent = 'pushNotification'
|
|
1110
|
+
export type PushNotificationCallback = (deviceId: string, notification: GenericPushNotification, device: MerossDevice) => void
|
|
1111
|
+
|
|
1112
|
+
export type ErrorEvent = 'error'
|
|
1113
|
+
export type CloudErrorCallback = (error: Error, deviceId: string | null) => void
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Filter options for finding devices.
|
|
1117
|
+
*
|
|
1118
|
+
* Used with MerossManager.findDevices() to filter the device list.
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* // Find online devices
|
|
1123
|
+
* const onlineDevices = manager.findDevices({ online_status: 1 });
|
|
1124
|
+
*
|
|
1125
|
+
* // Find specific device types
|
|
1126
|
+
* const plugs = manager.findDevices({ device_type: 'mss310' });
|
|
1127
|
+
*
|
|
1128
|
+
* // Find by custom filter function
|
|
1129
|
+
* const customDevices = manager.findDevices({
|
|
1130
|
+
* device_class: (device) => device.deviceType.startsWith('mss')
|
|
1131
|
+
* });
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
export interface FindDevicesFilters {
|
|
1135
|
+
/** Array of device UUIDs to filter by */
|
|
1136
|
+
device_uuids?: string[];
|
|
1137
|
+
/** Array of internal device IDs to filter by */
|
|
1138
|
+
internal_ids?: string[];
|
|
1139
|
+
/** Device type to filter by */
|
|
1140
|
+
device_type?: string;
|
|
1141
|
+
/** Device name to filter by */
|
|
1142
|
+
device_name?: string;
|
|
1143
|
+
/** Online status to filter by (0=connecting, 1=online, 2=offline, -1=unknown, 3=upgrading) */
|
|
1144
|
+
online_status?: number;
|
|
1145
|
+
/** Device class filter - can be a string, function, or array of filters */
|
|
1146
|
+
device_class?: string | ((device: MerossDevice) => boolean) | Array<string | ((device: MerossDevice) => boolean)>;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// Statistics types
|
|
1150
|
+
export class HttpRequestSample {
|
|
1151
|
+
readonly url: string;
|
|
1152
|
+
readonly method: string;
|
|
1153
|
+
readonly httpResponseCode: number;
|
|
1154
|
+
readonly apiResponseCode: number | null;
|
|
1155
|
+
readonly timestamp: number;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
export class HttpStat {
|
|
1159
|
+
readonly totalCalls: number;
|
|
1160
|
+
byHttpResponseCode(): Array<[number, number]>;
|
|
1161
|
+
byApiStatusCode(): Array<[string, number]>;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
export class HttpStatsResult {
|
|
1165
|
+
readonly globalStats: HttpStat;
|
|
1166
|
+
statsByUrl(url: string): HttpStat | null;
|
|
1167
|
+
deviceStats(): Array<[string, HttpStat]>;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
export class HttpStatsCounter {
|
|
1171
|
+
constructor(maxSamples?: number);
|
|
1172
|
+
notifyHttpRequest(requestUrl: string, method: string, httpResponseCode: number, apiResponseCode: number | null): void;
|
|
1173
|
+
getStats(timeWindowMs?: number): HttpStatsResult;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
export class ApiCallSample {
|
|
1177
|
+
readonly deviceUuid: string;
|
|
1178
|
+
readonly namespace: string;
|
|
1179
|
+
readonly method: string;
|
|
1180
|
+
readonly timestamp: number;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
export class ApiStat {
|
|
1184
|
+
readonly totalCalls: number;
|
|
1185
|
+
byMethodNamespace(): Array<[string, number]>;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
export class ApiStatsResult {
|
|
1189
|
+
readonly globalStats: ApiStat;
|
|
1190
|
+
statsByUuid(deviceUuid: string): ApiStat | null;
|
|
1191
|
+
deviceStats(): Array<[string, ApiStat]>;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
export class MqttStatsCounter {
|
|
1195
|
+
constructor(maxSamples?: number);
|
|
1196
|
+
readonly apiCalls: ApiCallSample[];
|
|
1197
|
+
readonly delayedCalls: ApiCallSample[];
|
|
1198
|
+
readonly droppedCalls: ApiCallSample[];
|
|
1199
|
+
notifyApiCall(deviceUuid: string, namespace: string, method: string): void;
|
|
1200
|
+
notifyDelayedCall(deviceUuid: string, namespace: string, method: string): void;
|
|
1201
|
+
notifyDroppedCall(deviceUuid: string, namespace: string, method: string): void;
|
|
1202
|
+
getApiStats(timeWindowMs?: number): ApiStatsResult;
|
|
1203
|
+
getDelayedApiStats(timeWindowMs?: number): ApiStatsResult;
|
|
1204
|
+
getDroppedApiStats(timeWindowMs?: number): ApiStatsResult;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Utility class for timer operations.
|
|
1209
|
+
*
|
|
1210
|
+
* Provides static methods for working with device timers, including time conversion,
|
|
1211
|
+
* day mask generation, and timer creation.
|
|
1212
|
+
*
|
|
1213
|
+
* @example
|
|
1214
|
+
* ```typescript
|
|
1215
|
+
* const minutes = TimerUtils.timeToMinutes('14:30');
|
|
1216
|
+
* const weekMask = TimerUtils.daysToWeekMask(['monday', 'wednesday', 'friday']);
|
|
1217
|
+
* const timer = TimerUtils.createTimer({
|
|
1218
|
+
* channel: 0,
|
|
1219
|
+
* time: '18:00',
|
|
1220
|
+
* days: ['monday', 'tuesday', 'wednesday'],
|
|
1221
|
+
* on: true
|
|
1222
|
+
* });
|
|
1223
|
+
* ```
|
|
1224
|
+
*/
|
|
1225
|
+
export class TimerUtils {
|
|
1226
|
+
/**
|
|
1227
|
+
* Converts a time string, Date, or minutes to total minutes since midnight.
|
|
1228
|
+
*
|
|
1229
|
+
* @param time - Time as string ('HH:MM'), Date object, or minutes number
|
|
1230
|
+
* @returns Total minutes since midnight
|
|
1231
|
+
*/
|
|
1232
|
+
static timeToMinutes(time: string | Date | number): number;
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Converts minutes since midnight to time string.
|
|
1236
|
+
*
|
|
1237
|
+
* @param minutes - Minutes since midnight
|
|
1238
|
+
* @returns Time string in 'HH:MM' format
|
|
1239
|
+
*/
|
|
1240
|
+
static minutesToTime(minutes: number): string;
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Converts an array of days to a week mask bitmask.
|
|
1244
|
+
*
|
|
1245
|
+
* @param days - Array of day names or numbers
|
|
1246
|
+
* @param repeat - Whether to repeat weekly (default: true)
|
|
1247
|
+
* @returns Week mask bitmask
|
|
1248
|
+
*/
|
|
1249
|
+
static daysToWeekMask(days: Array<string | number>, repeat?: boolean): number;
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* Generates a unique timer ID.
|
|
1253
|
+
*
|
|
1254
|
+
* @returns Timer ID string
|
|
1255
|
+
*/
|
|
1256
|
+
static generateTimerId(): string;
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Creates a timer object with the specified options.
|
|
1260
|
+
*
|
|
1261
|
+
* @param options - Timer options
|
|
1262
|
+
* @returns Timer object ready to be sent to device
|
|
1263
|
+
*/
|
|
1264
|
+
static createTimer(options: {
|
|
1265
|
+
channel?: number;
|
|
1266
|
+
alias?: string;
|
|
1267
|
+
time?: string | Date | number;
|
|
1268
|
+
days?: string[] | number[];
|
|
1269
|
+
on?: boolean;
|
|
1270
|
+
enabled?: boolean;
|
|
1271
|
+
type?: number;
|
|
1272
|
+
}): any;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Utility class for trigger operations.
|
|
1277
|
+
*
|
|
1278
|
+
* Provides static methods for working with device triggers, including duration
|
|
1279
|
+
* conversion and trigger creation.
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```typescript
|
|
1283
|
+
* const seconds = TriggerUtils.durationToSeconds('1h30m');
|
|
1284
|
+
* const duration = TriggerUtils.secondsToDuration(5400);
|
|
1285
|
+
* const trigger = TriggerUtils.createTrigger({
|
|
1286
|
+
* channel: 0,
|
|
1287
|
+
* duration: '2h',
|
|
1288
|
+
* days: ['monday', 'friday'],
|
|
1289
|
+
* enabled: true
|
|
1290
|
+
* });
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
export class TriggerUtils {
|
|
1294
|
+
/**
|
|
1295
|
+
* Converts a duration string or number to seconds.
|
|
1296
|
+
*
|
|
1297
|
+
* @param duration - Duration as string ('1h30m') or seconds number
|
|
1298
|
+
* @returns Total seconds
|
|
1299
|
+
*/
|
|
1300
|
+
static durationToSeconds(duration: string | number): number;
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* Converts seconds to duration string.
|
|
1304
|
+
*
|
|
1305
|
+
* @param seconds - Total seconds
|
|
1306
|
+
* @returns Duration string (e.g., '1h30m')
|
|
1307
|
+
*/
|
|
1308
|
+
static secondsToDuration(seconds: number): string;
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
* Creates a trigger object with the specified options.
|
|
1312
|
+
*
|
|
1313
|
+
* @param options - Trigger options
|
|
1314
|
+
* @returns Trigger object ready to be sent to device
|
|
1315
|
+
*/
|
|
1316
|
+
static createTrigger(options: {
|
|
1317
|
+
channel?: number;
|
|
1318
|
+
alias?: string;
|
|
1319
|
+
duration?: string | number;
|
|
1320
|
+
days?: string[] | number[];
|
|
1321
|
+
type?: number;
|
|
1322
|
+
enabled?: boolean;
|
|
1323
|
+
}): any;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
export interface DebugUtils {
|
|
1327
|
+
getErrorBudget(deviceUuid: string): number;
|
|
1328
|
+
resetErrorBudget(deviceUuid: string): void;
|
|
1329
|
+
getMqttStats(timeWindowMs?: number): ApiStatsResult | null;
|
|
1330
|
+
getHttpStats(timeWindowMs?: number): HttpStatsResult | null;
|
|
1331
|
+
getDelayedMqttStats(timeWindowMs?: number): ApiStatsResult | null;
|
|
1332
|
+
getDroppedMqttStats(timeWindowMs?: number): ApiStatsResult | null;
|
|
1333
|
+
enableStats(maxStatsSamples?: number): void;
|
|
1334
|
+
disableStats(): void;
|
|
1335
|
+
isStatsEnabled(): boolean;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
export function createDebugUtils(manager: MerossManager): DebugUtils;
|
|
1339
|
+
|
|
1340
|
+
export interface SubscriptionManagerOptions {
|
|
1341
|
+
/** Logger function for debug output */
|
|
1342
|
+
logger?: Logger;
|
|
1343
|
+
deviceStateInterval?: number;
|
|
1344
|
+
electricityInterval?: number;
|
|
1345
|
+
consumptionInterval?: number;
|
|
1346
|
+
httpDeviceListInterval?: number;
|
|
1347
|
+
smartCaching?: boolean;
|
|
1348
|
+
cacheMaxAge?: number;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* Device update callback data
|
|
1353
|
+
*/
|
|
1354
|
+
export interface DeviceUpdate {
|
|
1355
|
+
deviceUuid: string
|
|
1356
|
+
timestamp: number
|
|
1357
|
+
data?: Record<string, any>
|
|
1358
|
+
[key: string]: any
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
export class SubscriptionManager {
|
|
1362
|
+
constructor(manager: MerossManager, options?: SubscriptionManagerOptions);
|
|
1363
|
+
subscribe(device: MerossDevice, config?: SubscriptionManagerOptions, onUpdate?: (update: DeviceUpdate) => void): string;
|
|
1364
|
+
unsubscribe(deviceUuid: string, subscriptionId: string): void;
|
|
1365
|
+
subscribeToDeviceList(onUpdate?: (devices: DeviceDefinition[]) => void): string;
|
|
1366
|
+
unsubscribeFromDeviceList(subscriptionId: string): void;
|
|
1367
|
+
destroy(): void;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* Main Meross IoT cloud manager.
|
|
1372
|
+
*
|
|
1373
|
+
* Manages connections to Meross devices via cloud MQTT and local HTTP.
|
|
1374
|
+
* Handles device discovery, connection management, and provides access to device instances.
|
|
1375
|
+
*
|
|
1376
|
+
* @example
|
|
1377
|
+
* ```typescript
|
|
1378
|
+
* const httpClient = await MerossHttpClient.fromUserPassword({
|
|
1379
|
+
* email: 'user@example.com',
|
|
1380
|
+
* password: 'password'
|
|
1381
|
+
* });
|
|
1382
|
+
*
|
|
1383
|
+
* const manager = new MerossManager({ httpClient });
|
|
1384
|
+
* await manager.connect();
|
|
1385
|
+
*
|
|
1386
|
+
* manager.on('deviceInitialized', (deviceId, deviceDef, device) => {
|
|
1387
|
+
* console.log(`Device ${deviceId} initialized`);
|
|
1388
|
+
* });
|
|
1389
|
+
*
|
|
1390
|
+
* const devices = manager.getAllDevices();
|
|
1391
|
+
* ```
|
|
1392
|
+
*/
|
|
1393
|
+
export class MerossManager extends EventEmitter {
|
|
1394
|
+
/**
|
|
1395
|
+
* Creates a new MerossManager instance.
|
|
1396
|
+
*
|
|
1397
|
+
* @param options - Configuration options
|
|
1398
|
+
*/
|
|
1399
|
+
constructor(options: CloudOptions)
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Connects to the Meross cloud and initializes devices.
|
|
1403
|
+
*
|
|
1404
|
+
* @returns Promise resolving to the number of devices initialized
|
|
1405
|
+
* @throws {MerossError} If connection fails
|
|
1406
|
+
*/
|
|
1407
|
+
connect(): Promise<number>
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Registers a handler for device initialization events.
|
|
1411
|
+
*
|
|
1412
|
+
* @param name - Event name ('deviceInitialized')
|
|
1413
|
+
* @param handler - Callback function
|
|
1414
|
+
* @returns This instance for method chaining
|
|
1415
|
+
*/
|
|
1416
|
+
on(name: DeviceInitializedEvent, handler: DeviceInitializedCallback): this
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* Registers a handler for push notification events.
|
|
1420
|
+
*
|
|
1421
|
+
* @param name - Event name ('pushNotification')
|
|
1422
|
+
* @param handler - Callback function
|
|
1423
|
+
* @returns This instance for method chaining
|
|
1424
|
+
*/
|
|
1425
|
+
on(name: PushNotificationEvent, handler: PushNotificationCallback): this
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Registers a handler for error events.
|
|
1429
|
+
*
|
|
1430
|
+
* @param name - Event name ('error')
|
|
1431
|
+
* @param handler - Callback function
|
|
1432
|
+
* @returns This instance for method chaining
|
|
1433
|
+
*/
|
|
1434
|
+
on(name: ErrorEvent, handler: CloudErrorCallback): this
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Logs out and invalidates the current session.
|
|
1438
|
+
*
|
|
1439
|
+
* @returns Promise that resolves when logout is complete
|
|
1440
|
+
*/
|
|
1441
|
+
logout(): Promise<void>
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* Disconnects all devices.
|
|
1445
|
+
*
|
|
1446
|
+
* @param force - Whether to force disconnect immediately
|
|
1447
|
+
*/
|
|
1448
|
+
disconnectAll(force: boolean): void
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Gets a device by UUID.
|
|
1452
|
+
*
|
|
1453
|
+
* @param uuid - Device UUID
|
|
1454
|
+
* @returns Device instance or null if not found
|
|
1455
|
+
*/
|
|
1456
|
+
getDevice(uuid: string): MerossDevice | null
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* Finds devices matching the specified filters.
|
|
1460
|
+
*
|
|
1461
|
+
* @param filters - Optional filter criteria
|
|
1462
|
+
* @returns Array of matching device instances
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```typescript
|
|
1466
|
+
* const onlineDevices = manager.findDevices({ online_status: 1 });
|
|
1467
|
+
* const plugs = manager.findDevices({ device_type: 'mss310' });
|
|
1468
|
+
* ```
|
|
1469
|
+
*/
|
|
1470
|
+
findDevices(filters?: FindDevicesFilters): MerossDevice[]
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* Gets all initialized devices.
|
|
1474
|
+
*
|
|
1475
|
+
* @returns Array of all device instances
|
|
1476
|
+
*/
|
|
1477
|
+
getAllDevices(): MerossDevice[]
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* Gets the current token data.
|
|
1481
|
+
*
|
|
1482
|
+
* @returns Token data or null if not authenticated
|
|
1483
|
+
*/
|
|
1484
|
+
getTokenData(): TokenData | null
|
|
1485
|
+
|
|
1486
|
+
/** HTTP client instance */
|
|
1487
|
+
readonly httpClient: MerossHttpClient
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* HTTP client for Meross cloud API.
|
|
1493
|
+
*
|
|
1494
|
+
* Handles authentication and HTTP API requests to the Meross cloud.
|
|
1495
|
+
* Provides factory methods for easy initialization from credentials.
|
|
1496
|
+
*
|
|
1497
|
+
* @example
|
|
1498
|
+
* ```typescript
|
|
1499
|
+
* // Login with username/password
|
|
1500
|
+
* const httpClient = await MerossHttpClient.fromUserPassword({
|
|
1501
|
+
* email: 'user@example.com',
|
|
1502
|
+
* password: 'password'
|
|
1503
|
+
* });
|
|
1504
|
+
*
|
|
1505
|
+
* // Or use saved credentials
|
|
1506
|
+
* const httpClient = MerossHttpClient.fromCredentials({
|
|
1507
|
+
* token: '...',
|
|
1508
|
+
* key: '...',
|
|
1509
|
+
* userId: '...',
|
|
1510
|
+
* domain: '...'
|
|
1511
|
+
* });
|
|
1512
|
+
*
|
|
1513
|
+
* const devices = await httpClient.getDevices();
|
|
1514
|
+
* ```
|
|
1515
|
+
*/
|
|
1516
|
+
export class MerossHttpClient {
|
|
1517
|
+
/**
|
|
1518
|
+
* Creates a new MerossHttpClient instance.
|
|
1519
|
+
*
|
|
1520
|
+
* @param options - Client configuration options
|
|
1521
|
+
*/
|
|
1522
|
+
constructor(options?: {
|
|
1523
|
+
logger?: Logger;
|
|
1524
|
+
timeout?: number;
|
|
1525
|
+
autoRetryOnBadDomain?: boolean;
|
|
1526
|
+
mqttDomain?: string | null;
|
|
1527
|
+
enableStats?: boolean;
|
|
1528
|
+
maxStatsSamples?: number;
|
|
1529
|
+
});
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Sets the authentication token.
|
|
1533
|
+
*
|
|
1534
|
+
* @param token - Authentication token
|
|
1535
|
+
*/
|
|
1536
|
+
setToken(token: string): void;
|
|
1537
|
+
|
|
1538
|
+
/**
|
|
1539
|
+
* Sets the HTTP API domain.
|
|
1540
|
+
*
|
|
1541
|
+
* @param domain - API domain (e.g., 'us.meross.com')
|
|
1542
|
+
*/
|
|
1543
|
+
setHttpDomain(domain: string): void;
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* Sets the MQTT domain.
|
|
1547
|
+
*
|
|
1548
|
+
* @param domain - MQTT domain or null to use default
|
|
1549
|
+
*/
|
|
1550
|
+
setMqttDomain(domain: string | null): void;
|
|
1551
|
+
|
|
1552
|
+
/** HTTP statistics counter (null if stats not enabled) */
|
|
1553
|
+
readonly stats: HttpStatsCounter | null;
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* Logs in with email and password.
|
|
1557
|
+
*
|
|
1558
|
+
* @param email - User email address
|
|
1559
|
+
* @param password - User password
|
|
1560
|
+
* @param mfaCode - Optional MFA code if required
|
|
1561
|
+
* @returns Promise resolving to login response with token data
|
|
1562
|
+
* @throws {MFARequiredError} If MFA is required
|
|
1563
|
+
* @throws {AuthenticationError} If login fails
|
|
1564
|
+
*/
|
|
1565
|
+
login(email: string, password: string, mfaCode?: string): Promise<{
|
|
1566
|
+
token: string;
|
|
1567
|
+
key: string;
|
|
1568
|
+
userId: string;
|
|
1569
|
+
email: string;
|
|
1570
|
+
mqttDomain?: string;
|
|
1571
|
+
}>;
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
* Gets the list of devices for the authenticated user.
|
|
1575
|
+
*
|
|
1576
|
+
* @returns Promise resolving to array of device definitions
|
|
1577
|
+
* @throws {UnauthorizedError} If not authenticated
|
|
1578
|
+
*/
|
|
1579
|
+
getDevices(): Promise<DeviceDefinition[]>;
|
|
1580
|
+
|
|
1581
|
+
/**
|
|
1582
|
+
* Gets subdevices for a hub device.
|
|
1583
|
+
*
|
|
1584
|
+
* @param deviceUuid - Hub device UUID
|
|
1585
|
+
* @returns Promise resolving to array of subdevice definitions
|
|
1586
|
+
*/
|
|
1587
|
+
getSubDevices(deviceUuid: string): Promise<any[]>;
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* Logs out and invalidates the current session.
|
|
1591
|
+
*
|
|
1592
|
+
* @returns Promise that resolves when logout is complete
|
|
1593
|
+
*/
|
|
1594
|
+
logout(): Promise<void>;
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* Factory method: Creates an HTTP client from username/password credentials.
|
|
1598
|
+
*
|
|
1599
|
+
* This method handles login and returns a configured client instance.
|
|
1600
|
+
*
|
|
1601
|
+
* @param options - Login options including email and password
|
|
1602
|
+
* @returns Promise resolving to configured MerossHttpClient instance
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* ```typescript
|
|
1606
|
+
* const httpClient = await MerossHttpClient.fromUserPassword({
|
|
1607
|
+
* email: 'user@example.com',
|
|
1608
|
+
* password: 'password',
|
|
1609
|
+
* mfaCode: '123456' // if MFA is enabled
|
|
1610
|
+
* });
|
|
1611
|
+
* ```
|
|
1612
|
+
*/
|
|
1613
|
+
static fromUserPassword(options: {
|
|
1614
|
+
email: string;
|
|
1615
|
+
password: string;
|
|
1616
|
+
mfaCode?: string;
|
|
1617
|
+
logger?: Logger;
|
|
1618
|
+
timeout?: number;
|
|
1619
|
+
autoRetryOnBadDomain?: boolean;
|
|
1620
|
+
enableStats?: boolean;
|
|
1621
|
+
maxStatsSamples?: number;
|
|
1622
|
+
}): Promise<MerossHttpClient>;
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* Factory method: Creates an HTTP client from saved credentials.
|
|
1626
|
+
*
|
|
1627
|
+
* Use this when you have previously saved token data from a login.
|
|
1628
|
+
*
|
|
1629
|
+
* @param credentials - Saved credential data
|
|
1630
|
+
* @param options - Optional client configuration
|
|
1631
|
+
* @returns Configured MerossHttpClient instance
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* ```typescript
|
|
1635
|
+
* const httpClient = MerossHttpClient.fromCredentials({
|
|
1636
|
+
* token: savedToken,
|
|
1637
|
+
* key: savedKey,
|
|
1638
|
+
* userId: savedUserId,
|
|
1639
|
+
* domain: savedDomain,
|
|
1640
|
+
* mqttDomain: savedMqttDomain
|
|
1641
|
+
* });
|
|
1642
|
+
* ```
|
|
1643
|
+
*/
|
|
1644
|
+
static fromCredentials(credentials: {
|
|
1645
|
+
token: string;
|
|
1646
|
+
key: string;
|
|
1647
|
+
userId: string;
|
|
1648
|
+
domain: string;
|
|
1649
|
+
mqttDomain?: string;
|
|
1650
|
+
}, options?: {
|
|
1651
|
+
logger?: Logger;
|
|
1652
|
+
timeout?: number;
|
|
1653
|
+
autoRetryOnBadDomain?: boolean;
|
|
1654
|
+
enableStats?: boolean;
|
|
1655
|
+
maxStatsSamples?: number;
|
|
1656
|
+
}): MerossHttpClient;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
/**
|
|
1660
|
+
* Represents a Meross device.
|
|
1661
|
+
*
|
|
1662
|
+
* Provides methods to control and query Meross devices. Devices are automatically
|
|
1663
|
+
* initialized when the manager connects. This class extends EventEmitter and emits
|
|
1664
|
+
* events for device state changes, push notifications, and connection status.
|
|
1665
|
+
*
|
|
1666
|
+
* @example
|
|
1667
|
+
* ```typescript
|
|
1668
|
+
* const device = manager.getDevice('device-uuid');
|
|
1669
|
+
*
|
|
1670
|
+
* device.on('connected', () => {
|
|
1671
|
+
* console.log('Device connected');
|
|
1672
|
+
* });
|
|
1673
|
+
*
|
|
1674
|
+
* device.on('pushNotification', (notification) => {
|
|
1675
|
+
* if (notification instanceof ToggleXPushNotification) {
|
|
1676
|
+
* console.log('Toggle state changed');
|
|
1677
|
+
* }
|
|
1678
|
+
* });
|
|
1679
|
+
*
|
|
1680
|
+
* await device.turnOn();
|
|
1681
|
+
* ```
|
|
1682
|
+
*/
|
|
1683
|
+
export class MerossDevice extends EventEmitter {
|
|
1684
|
+
/**
|
|
1685
|
+
* Registers a handler for push notification events.
|
|
1686
|
+
*
|
|
1687
|
+
* @param event - Event name ('pushNotification')
|
|
1688
|
+
* @param listener - Callback function receiving the notification
|
|
1689
|
+
* @returns This instance for method chaining
|
|
1690
|
+
*/
|
|
1691
|
+
on(event: 'pushNotification', listener: (notification: GenericPushNotification) => void): this;
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* Registers a handler for data events.
|
|
1695
|
+
*
|
|
1696
|
+
* @param event - Event name ('data')
|
|
1697
|
+
* @param listener - Callback function receiving namespace and payload
|
|
1698
|
+
* @returns This instance for method chaining
|
|
1699
|
+
*/
|
|
1700
|
+
on(event: 'data', listener: (namespace: string, payload: Record<string, any>) => void): this;
|
|
1701
|
+
|
|
1702
|
+
/**
|
|
1703
|
+
* Registers a handler for raw data events.
|
|
1704
|
+
*
|
|
1705
|
+
* @param event - Event name ('rawData')
|
|
1706
|
+
* @param listener - Callback function receiving raw message
|
|
1707
|
+
* @returns This instance for method chaining
|
|
1708
|
+
*/
|
|
1709
|
+
on(event: 'rawData', listener: (message: Record<string, any>) => void): this;
|
|
1710
|
+
|
|
1711
|
+
/**
|
|
1712
|
+
* Registers a handler for connected events.
|
|
1713
|
+
*
|
|
1714
|
+
* @param event - Event name ('connected')
|
|
1715
|
+
* @param listener - Callback function
|
|
1716
|
+
* @returns This instance for method chaining
|
|
1717
|
+
*/
|
|
1718
|
+
on(event: 'connected', listener: () => void): this;
|
|
1719
|
+
|
|
1720
|
+
/**
|
|
1721
|
+
* Registers a handler for close events.
|
|
1722
|
+
*
|
|
1723
|
+
* @param event - Event name ('close')
|
|
1724
|
+
* @param listener - Callback function
|
|
1725
|
+
* @returns This instance for method chaining
|
|
1726
|
+
*/
|
|
1727
|
+
on(event: 'close', listener: () => void): this;
|
|
1728
|
+
|
|
1729
|
+
/**
|
|
1730
|
+
* Registers a handler for error events.
|
|
1731
|
+
*
|
|
1732
|
+
* @param event - Event name ('error')
|
|
1733
|
+
* @param listener - Callback function receiving the error
|
|
1734
|
+
* @returns This instance for method chaining
|
|
1735
|
+
*/
|
|
1736
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
1737
|
+
|
|
1738
|
+
/**
|
|
1739
|
+
* Registers a handler for online status change events.
|
|
1740
|
+
*
|
|
1741
|
+
* @param event - Event name ('onlineStatusChange')
|
|
1742
|
+
* @param listener - Callback function receiving new and old status
|
|
1743
|
+
* @returns This instance for method chaining
|
|
1744
|
+
*/
|
|
1745
|
+
on(event: 'onlineStatusChange', listener: (newStatus: number, oldStatus: number) => void): this;
|
|
1746
|
+
/**
|
|
1747
|
+
* Connects the device to MQTT.
|
|
1748
|
+
*
|
|
1749
|
+
* @deprecated Devices are automatically connected by the manager. This method is kept for backward compatibility.
|
|
1750
|
+
*/
|
|
1751
|
+
connect(): void
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* Disconnects the device from MQTT.
|
|
1755
|
+
*
|
|
1756
|
+
* @param force - Whether to force immediate disconnect
|
|
1757
|
+
* @deprecated Use manager.disconnectAll() instead. This method is kept for backward compatibility.
|
|
1758
|
+
*/
|
|
1759
|
+
disconnect(force: boolean): void
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* Sets a known local IP address for the device.
|
|
1763
|
+
*
|
|
1764
|
+
* This helps the library use LAN HTTP communication when available.
|
|
1765
|
+
*
|
|
1766
|
+
* @param ip - Local IP address (e.g., '192.168.1.100')
|
|
1767
|
+
*/
|
|
1768
|
+
setKnownLocalIp(ip: string): void
|
|
1769
|
+
|
|
1770
|
+
/**
|
|
1771
|
+
* Removes the known local IP address.
|
|
1772
|
+
*/
|
|
1773
|
+
removeKnownLocalIp(): void
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* Checks if the device supports encryption.
|
|
1777
|
+
*
|
|
1778
|
+
* @returns True if encryption is supported
|
|
1779
|
+
*/
|
|
1780
|
+
supportEncryption(): boolean
|
|
1781
|
+
|
|
1782
|
+
/**
|
|
1783
|
+
* Checks if an encryption key is set for this device.
|
|
1784
|
+
*
|
|
1785
|
+
* @returns True if encryption key is set
|
|
1786
|
+
*/
|
|
1787
|
+
isEncryptionKeySet(): boolean
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* Sets the encryption key for this device.
|
|
1791
|
+
*
|
|
1792
|
+
* Required for devices that support encryption.
|
|
1793
|
+
*
|
|
1794
|
+
* @param uuid - Device UUID
|
|
1795
|
+
* @param mrskey - Encryption key
|
|
1796
|
+
* @param mac - MAC address
|
|
1797
|
+
*/
|
|
1798
|
+
setEncryptionKey(uuid: string, mrskey: string, mac: string): void
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Encrypts a message for this device.
|
|
1802
|
+
*
|
|
1803
|
+
* @param messageData - Message data to encrypt
|
|
1804
|
+
* @returns Encrypted message string
|
|
1805
|
+
*/
|
|
1806
|
+
encryptMessage(messageData: string | Buffer): string
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* Decrypts a message from this device.
|
|
1810
|
+
*
|
|
1811
|
+
* @param encryptedData - Encrypted message data
|
|
1812
|
+
* @returns Decrypted message buffer
|
|
1813
|
+
*/
|
|
1814
|
+
decryptMessage(encryptedData: string | Buffer): Buffer
|
|
1815
|
+
|
|
1816
|
+
/**
|
|
1817
|
+
* Updates device abilities.
|
|
1818
|
+
*
|
|
1819
|
+
* @param abilities - Abilities object containing supported features
|
|
1820
|
+
*/
|
|
1821
|
+
updateAbilities(abilities: Record<string, any>): void
|
|
1822
|
+
|
|
1823
|
+
/**
|
|
1824
|
+
* Updates the device MAC address.
|
|
1825
|
+
*
|
|
1826
|
+
* @param mac - MAC address string
|
|
1827
|
+
*/
|
|
1828
|
+
updateMacAddress(mac: string): void
|
|
1829
|
+
|
|
1830
|
+
readonly macAddress: string | null
|
|
1831
|
+
readonly firmwareVersion: string
|
|
1832
|
+
readonly hardwareVersion: string
|
|
1833
|
+
readonly lanIp: string | null
|
|
1834
|
+
readonly mqttHost: string | null
|
|
1835
|
+
readonly mqttPort: number | null
|
|
1836
|
+
/** Device abilities object containing supported features and namespaces */
|
|
1837
|
+
readonly abilities: Record<string, any> | null
|
|
1838
|
+
readonly lastFullUpdateTimestamp: number | null
|
|
1839
|
+
readonly onlineStatus: number
|
|
1840
|
+
readonly isOnline: boolean
|
|
1841
|
+
readonly internalId: string
|
|
1842
|
+
readonly channels: ChannelInfo[]
|
|
1843
|
+
readonly cachedHttpInfo: HttpDeviceInfo | null
|
|
1844
|
+
|
|
1845
|
+
/**
|
|
1846
|
+
* Validates the current device state.
|
|
1847
|
+
*
|
|
1848
|
+
* @returns True if state is valid
|
|
1849
|
+
*/
|
|
1850
|
+
validateState(): boolean
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* Refreshes device state by querying the device.
|
|
1854
|
+
*
|
|
1855
|
+
* @param timeout - Optional timeout in milliseconds
|
|
1856
|
+
* @returns Promise that resolves when state is refreshed
|
|
1857
|
+
*/
|
|
1858
|
+
refreshState(timeout?: number): Promise<void>
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Looks up channel information by ID or name.
|
|
1862
|
+
*
|
|
1863
|
+
* @param channelIdOrName - Channel index or name
|
|
1864
|
+
* @returns ChannelInfo instance
|
|
1865
|
+
* @throws {Error} If channel not found
|
|
1866
|
+
*/
|
|
1867
|
+
lookupChannel(channelIdOrName: number | string): ChannelInfo
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* Updates device state from HTTP device info.
|
|
1871
|
+
*
|
|
1872
|
+
* @param deviceInfo - HTTP device information
|
|
1873
|
+
* @returns Promise resolving to this device instance
|
|
1874
|
+
*/
|
|
1875
|
+
updateFromHttpState(deviceInfo: HttpDeviceInfo): Promise<MerossDevice>
|
|
1876
|
+
|
|
1877
|
+
/**
|
|
1878
|
+
* Publishes a message to the device.
|
|
1879
|
+
*
|
|
1880
|
+
* @param method - Message method ('GET' or 'SET')
|
|
1881
|
+
* @param namespace - Namespace for the message
|
|
1882
|
+
* @param payload - Message payload
|
|
1883
|
+
* @returns Promise resolving to device response
|
|
1884
|
+
*/
|
|
1885
|
+
publishMessage(method: 'GET' | 'SET', namespace: string, payload: any): Promise<any>
|
|
1886
|
+
|
|
1887
|
+
getSystemAllData(): Promise<any>
|
|
1888
|
+
getSystemDebug(): Promise<any>
|
|
1889
|
+
getSystemAbilities(): Promise<any>
|
|
1890
|
+
getSystemRuntime(): Promise<any>
|
|
1891
|
+
getSystemDNDMode(): Promise<any>
|
|
1892
|
+
getEncryptSuite(): Promise<any>
|
|
1893
|
+
getEncryptECDHE(): Promise<any>
|
|
1894
|
+
getOnlineStatus(): Promise<any>
|
|
1895
|
+
getConfigWifiList(): Promise<any>
|
|
1896
|
+
getConfigTrace(): Promise<any>
|
|
1897
|
+
getControlPowerConsumption(options?: { channel?: number }): Promise<any>
|
|
1898
|
+
getControlPowerConsumptionX(options?: { channel?: number }): Promise<GetControlPowerConsumptionXResponse>
|
|
1899
|
+
getControlElectricity(options?: { channel?: number }): Promise<GetControlElectricityResponse>
|
|
1900
|
+
getPowerConsumption(options?: { channel?: number }): Promise<Array<{date: Date, totalConsumptionKwh: number}>>
|
|
1901
|
+
getPowerConsumptionX(options?: { channel?: number }): Promise<Array<{date: Date, totalConsumptionKwh: number}>>
|
|
1902
|
+
getRawPowerConsumption(options?: { channel?: number }): Promise<any>
|
|
1903
|
+
getRawPowerConsumptionX(options?: { channel?: number }): Promise<any>
|
|
1904
|
+
getElectricity(options?: { channel?: number }): Promise<{amperage: number, voltage: number, wattage: number, sampleTimestamp: Date}>
|
|
1905
|
+
getRawElectricity(options?: { channel?: number }): Promise<any>
|
|
1906
|
+
getTimerX(options?: { channel?: number; timerId?: string }): Promise<any>
|
|
1907
|
+
setTimerX(options: { channel?: number; alias?: string; time?: string; days?: string[]; on?: boolean; enabled?: boolean; type?: number; timerx?: any }): Promise<any>
|
|
1908
|
+
deleteTimerX(options: { timerId: string; channel?: number }): Promise<any>
|
|
1909
|
+
findTimerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1910
|
+
deleteTimerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1911
|
+
enableTimerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1912
|
+
disableTimerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1913
|
+
deleteAllTimers(options?: { channel?: number }): Promise<any>
|
|
1914
|
+
getTriggerX(options?: { channel?: number }): Promise<any>
|
|
1915
|
+
deleteTriggerX(options: { triggerId: string; channel?: number }): Promise<any>
|
|
1916
|
+
findTriggerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1917
|
+
deleteTriggerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1918
|
+
enableTriggerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1919
|
+
disableTriggerByAlias(options: { alias: string; channel?: number }): Promise<any>
|
|
1920
|
+
deleteAllTriggers(options?: { channel?: number }): Promise<any>
|
|
1921
|
+
getSmokeConfig(options?: { channel?: number; subId?: string }): Promise<any>
|
|
1922
|
+
getSensorHistory(options: { channel?: number; capacity: number }): Promise<any>
|
|
1923
|
+
getThermostatSchedule(options?: { channel?: number }): Promise<any>
|
|
1924
|
+
getThermostatTimer(options?: { channel?: number }): Promise<any>
|
|
1925
|
+
getAlarmStatus(options?: { channel?: number }): Promise<any>
|
|
1926
|
+
getRollerShutterState(): Promise<any>
|
|
1927
|
+
getRollerShutterPosition(): Promise<any>
|
|
1928
|
+
getRollerShutterConfig(): Promise<any>
|
|
1929
|
+
getFilterMaintenance(): Promise<any>
|
|
1930
|
+
getPhysicalLockState(): Promise<any>
|
|
1931
|
+
getFanState(): Promise<any>
|
|
1932
|
+
|
|
1933
|
+
setToggle(onoff: boolean): Promise<any>
|
|
1934
|
+
setToggleX(options: { channel?: number; onoff: boolean }): Promise<any>
|
|
1935
|
+
controlBind(payload: any): Promise<any>
|
|
1936
|
+
controlUnbind(payload: any): Promise<any>
|
|
1937
|
+
controlTrigger(channel: number, payload: any): Promise<any>
|
|
1938
|
+
setTriggerX(options: { channel?: number; alias?: string; duration?: string; days?: string[]; type?: number; enabled?: boolean; triggerx?: any }): Promise<any>
|
|
1939
|
+
setSpray(options: { channel?: number; mode: SprayMode | number }): Promise<any>
|
|
1940
|
+
getSprayState(): Promise<any>
|
|
1941
|
+
getCachedSprayState(channel?: number): SprayState | undefined
|
|
1942
|
+
getCurrentSprayMode(channel?: number): number | undefined
|
|
1943
|
+
setRollerShutterPosition(options: { channel?: number; position: number }): Promise<any>
|
|
1944
|
+
setRollerShutterUp(options?: { channel?: number }): Promise<any>
|
|
1945
|
+
setRollerShutterDown(options?: { channel?: number }): Promise<any>
|
|
1946
|
+
setRollerShutterStop(options?: { channel?: number }): Promise<any>
|
|
1947
|
+
openRollerShutter(options?: { channel?: number }): Promise<any>
|
|
1948
|
+
closeRollerShutter(options?: { channel?: number }): Promise<any>
|
|
1949
|
+
stopRollerShutter(options?: { channel?: number }): Promise<any>
|
|
1950
|
+
getCachedRollerShutterState(channel?: number): RollerShutterState | undefined
|
|
1951
|
+
getRollerShutterState(options?: { channel?: number }): Promise<any>
|
|
1952
|
+
getRollerShutterPosition(options?: { channel?: number }): Promise<any>
|
|
1953
|
+
getRollerShutterConfig(options?: { channel?: number }): Promise<any>
|
|
1954
|
+
setGarageDoor(options: { channel?: number; open: boolean }): Promise<any>
|
|
1955
|
+
getGarageDoorState(options?: { channel?: number }): Promise<any>
|
|
1956
|
+
getGarageDoorMultipleState(): Promise<any>
|
|
1957
|
+
getCachedGarageDoorState(channel?: number): GarageDoorState | undefined
|
|
1958
|
+
isGarageDoorOpened(channel?: number): boolean | undefined
|
|
1959
|
+
isGarageDoorClosed(channel?: number): boolean | undefined
|
|
1960
|
+
getGarageDoorConfig(options?: { channel?: number }): Promise<any>
|
|
1961
|
+
openGarageDoor(options?: { channel?: number }): Promise<any>
|
|
1962
|
+
closeGarageDoor(options?: { channel?: number }): Promise<any>
|
|
1963
|
+
toggleGarageDoor(options?: { channel?: number }): Promise<any>
|
|
1964
|
+
setLight(light: LightData): Promise<any>
|
|
1965
|
+
getLightState(options?: { channel?: number }): Promise<any>
|
|
1966
|
+
getCachedLightState(channel?: number): LightState | undefined
|
|
1967
|
+
getLightIsOn(channel?: number): boolean | undefined
|
|
1968
|
+
getLightRgbColor(channel?: number): [number, number, number] | undefined
|
|
1969
|
+
getLightBrightness(channel?: number): number | undefined
|
|
1970
|
+
getLightTemperature(channel?: number): number | undefined
|
|
1971
|
+
getLightMode(channel?: number): number | undefined
|
|
1972
|
+
getSupportsRgb(channel?: number): boolean
|
|
1973
|
+
getSupportsLuminance(channel?: number): boolean
|
|
1974
|
+
getSupportsTemperature(channel?: number): boolean
|
|
1975
|
+
/**
|
|
1976
|
+
* Turns the device on.
|
|
1977
|
+
*
|
|
1978
|
+
* @param options - Optional channel specification
|
|
1979
|
+
* @returns Promise resolving to device response
|
|
1980
|
+
*
|
|
1981
|
+
* @example
|
|
1982
|
+
* ```typescript
|
|
1983
|
+
* await device.turnOn();
|
|
1984
|
+
* await device.turnOn({ channel: 1 });
|
|
1985
|
+
* ```
|
|
1986
|
+
*/
|
|
1987
|
+
turnOn(options?: { channel?: number }): Promise<any>
|
|
1988
|
+
|
|
1989
|
+
/**
|
|
1990
|
+
* Turns the device off.
|
|
1991
|
+
*
|
|
1992
|
+
* @param options - Optional channel specification
|
|
1993
|
+
* @returns Promise resolving to device response
|
|
1994
|
+
*
|
|
1995
|
+
* @example
|
|
1996
|
+
* ```typescript
|
|
1997
|
+
* await device.turnOff();
|
|
1998
|
+
* await device.turnOff({ channel: 1 });
|
|
1999
|
+
* ```
|
|
2000
|
+
*/
|
|
2001
|
+
turnOff(options?: { channel?: number }): Promise<any>
|
|
2002
|
+
|
|
2003
|
+
/**
|
|
2004
|
+
* Sets the light color, brightness, and/or temperature.
|
|
2005
|
+
*
|
|
2006
|
+
* @param options - Light color options
|
|
2007
|
+
* @returns Promise resolving to device response
|
|
2008
|
+
*
|
|
2009
|
+
* @example
|
|
2010
|
+
* ```typescript
|
|
2011
|
+
* await device.setLightColor({
|
|
2012
|
+
* channel: 0,
|
|
2013
|
+
* rgb: [255, 0, 0], // Red
|
|
2014
|
+
* luminance: 50,
|
|
2015
|
+
* onoff: true
|
|
2016
|
+
* });
|
|
2017
|
+
* ```
|
|
2018
|
+
*/
|
|
2019
|
+
setLightColor(options?: LightColorOptions): Promise<any>
|
|
2020
|
+
setDiffuserSpray(options: { channel?: number; mode: number }): Promise<any>
|
|
2021
|
+
setDiffuserLight(light: LightData): Promise<any>
|
|
2022
|
+
getDiffuserLightState(options?: { channel?: number }): Promise<any>
|
|
2023
|
+
getDiffuserSprayState(options?: { channel?: number }): Promise<any>
|
|
2024
|
+
getCachedDiffuserLightState(channel?: number): DiffuserLightState | undefined
|
|
2025
|
+
getDiffuserLightMode(channel?: number): number | undefined
|
|
2026
|
+
getDiffuserLightBrightness(channel?: number): number | undefined
|
|
2027
|
+
getDiffuserLightRgbColor(channel?: number): [number, number, number] | undefined
|
|
2028
|
+
getDiffuserLightIsOn(channel?: number): boolean | undefined
|
|
2029
|
+
getCachedDiffuserSprayState(channel?: number): DiffuserSprayState | undefined
|
|
2030
|
+
getDiffuserSprayMode(channel?: number): number | undefined
|
|
2031
|
+
getCurrentSprayMode(channel?: number): number | undefined
|
|
2032
|
+
setThermostatMode(options: { channel?: number; partialUpdate?: boolean; mode?: number; onoff?: number; heatTemperature?: number; coolTemperature?: number; ecoTemperature?: number; manualTemperature?: number }): Promise<any>
|
|
2033
|
+
setThermostatModeB(options: { channel?: number; state?: number }): Promise<any>
|
|
2034
|
+
setThermostatWindowOpened(options: { channel?: number; windowOpened: boolean }): Promise<any>
|
|
2035
|
+
getThermostatMode(options?: { channel?: number }): Promise<any>
|
|
2036
|
+
getThermostatModeB(options?: { channel?: number }): Promise<any>
|
|
2037
|
+
getThermostatWindowOpened(options?: { channel?: number }): Promise<any>
|
|
2038
|
+
getCachedThermostatState(channel?: number): ThermostatState | undefined
|
|
2039
|
+
getCachedThermostatModeBState(channel?: number): ThermostatState | undefined
|
|
2040
|
+
setChildLock(options: { lockData: any }): Promise<any>
|
|
2041
|
+
controlFan(channel: number, speed: number, maxSpeed: number): Promise<any>
|
|
2042
|
+
setDNDMode(options: { mode: boolean | number }): Promise<any>
|
|
2043
|
+
getCachedPresenceSensorState(channel?: number): PresenceSensorState | undefined
|
|
2044
|
+
getCachedToggleState(channel?: number): ToggleState | undefined
|
|
2045
|
+
getPresence(channel?: number): { value: number; isPresent: boolean; state: number; distance: number; distanceRaw: number; timestamp: number; times: number } | null
|
|
2046
|
+
getLight(channel?: number): { value: number; timestamp: number } | null
|
|
2047
|
+
getAllSensorReadings(channel?: number): { presence: Record<string, any> | null; light: Record<string, any> | null }
|
|
2048
|
+
getPresenceConfig(options?: { channel?: number }): Promise<any>
|
|
2049
|
+
setPresenceConfig(options: { channel?: number; partialUpdate?: boolean; configData?: any; mode?: any; sensitivity?: any; distance?: any; noBodyTime?: any; mthx?: any }): Promise<any>
|
|
2050
|
+
getPresenceStudy(options?: { channel?: number }): Promise<any>
|
|
2051
|
+
setPresenceStudy(options: { channel?: number; partialUpdate?: boolean; studyData?: any }): Promise<any>
|
|
2052
|
+
getLatestSensorReadings(options?: { dataTypes?: string[] }): Promise<any>
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
export class MerossSubDevice extends MerossDevice {
|
|
2056
|
+
readonly subdeviceId: string
|
|
2057
|
+
readonly hub: MerossHubDevice
|
|
2058
|
+
readonly type: string
|
|
2059
|
+
readonly name: string
|
|
2060
|
+
handleSubdeviceNotification(namespace: string, data: any): Promise<void>
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
export class HubTempHumSensor extends MerossSubDevice {
|
|
2064
|
+
getLastSampledTemperature(): number | null
|
|
2065
|
+
getLastSampledHumidity(): number | null
|
|
2066
|
+
getLastSampledTime(): Date | null
|
|
2067
|
+
getMinSupportedTemperature(): number | null
|
|
2068
|
+
getMaxSupportedTemperature(): number | null
|
|
2069
|
+
getLux(): number | null
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
export class HubThermostatValve extends MerossSubDevice {
|
|
2073
|
+
isOn(): boolean
|
|
2074
|
+
turnOn(): Promise<void>
|
|
2075
|
+
turnOff(): Promise<void>
|
|
2076
|
+
toggle(): Promise<void>
|
|
2077
|
+
getMode(): number | undefined
|
|
2078
|
+
setMode(mode: number): Promise<void>
|
|
2079
|
+
getTargetTemperature(): number | null
|
|
2080
|
+
setTargetTemperature(temperature: number): Promise<void>
|
|
2081
|
+
getLastSampledTemperature(): number | null
|
|
2082
|
+
getMinSupportedTemperature(): number | null
|
|
2083
|
+
getMaxSupportedTemperature(): number | null
|
|
2084
|
+
isHeating(): boolean
|
|
2085
|
+
isWindowOpen(): boolean
|
|
2086
|
+
getSupportedPresets(): string[]
|
|
2087
|
+
getPresetTemperature(preset: string): number | null
|
|
2088
|
+
setPresetTemperature(preset: string, temperature: number): Promise<void>
|
|
2089
|
+
getAdjust(): number | null
|
|
2090
|
+
setAdjust(temperature: number): Promise<void>
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
export class HubWaterLeakSensor extends MerossSubDevice {
|
|
2094
|
+
isLeaking(): boolean | null
|
|
2095
|
+
getLatestSampleTime(): number | null
|
|
2096
|
+
getLatestDetectedWaterLeakTs(): number | null
|
|
2097
|
+
getLastEvents(): Array<{ leaking: boolean, timestamp: number }>
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
export class HubSmokeDetector extends MerossSubDevice {
|
|
2101
|
+
getSmokeAlarmStatus(): number | null
|
|
2102
|
+
getInterConnStatus(): number | null
|
|
2103
|
+
getLastStatusUpdate(): number | null
|
|
2104
|
+
muteAlarm(muteSmoke?: boolean): Promise<any>
|
|
2105
|
+
getTestEvents(): Array<{ type: number, timestamp: number }>
|
|
2106
|
+
refreshAlarmStatus(): Promise<any>
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
export class MerossHubDevice extends MerossDevice {
|
|
2110
|
+
getSubdevices(): MerossSubDevice[]
|
|
2111
|
+
getSubdevice(subdeviceId: string): MerossSubDevice | null
|
|
2112
|
+
registerSubdevice(subdevice: MerossSubDevice): void
|
|
2113
|
+
getHubBattery(): Promise<any>
|
|
2114
|
+
getHubSubdeviceList(): Promise<any>
|
|
2115
|
+
getHubOnline(): Promise<any>
|
|
2116
|
+
getHubException(): Promise<any>
|
|
2117
|
+
getHubReport(): Promise<any>
|
|
2118
|
+
setHubPairSubDev(): Promise<any>
|
|
2119
|
+
setHubSubDeviceBeep(subIds: string | string[], onoff: boolean): Promise<any>
|
|
2120
|
+
getHubSubDeviceBeep(subIds: string | string[]): Promise<any>
|
|
2121
|
+
getHubSubDeviceMotorAdjust(subIds: string | string[]): Promise<any>
|
|
2122
|
+
setHubSubDeviceMotorAdjust(adjustData: any): Promise<any>
|
|
2123
|
+
getHubSubDeviceVersion(subIds?: string[]): Promise<any>
|
|
2124
|
+
getAllSensors(sensorIds: string[] | string): Promise<any>
|
|
2125
|
+
getLatestHubSensorReadings(sensorIds: string[] | string, dataTypes?: string[]): Promise<any>
|
|
2126
|
+
getTempHumSensor(sensorIds: string[] | string): Promise<any>
|
|
2127
|
+
getAlertSensor(sensorIds: string[] | string): Promise<any>
|
|
2128
|
+
getSmokeAlarmStatus(sensorIds: string[] | string): Promise<any>
|
|
2129
|
+
getWaterLeakSensor(sensorIds: string[] | string): Promise<any>
|
|
2130
|
+
getHubSensorAdjust(sensorIds?: string[]): Promise<any>
|
|
2131
|
+
setHubSensorAdjust(adjustData: any): Promise<any>
|
|
2132
|
+
getHubSensorDoorWindow(sensorIds?: string[]): Promise<any>
|
|
2133
|
+
setHubSensorDoorWindow(doorWindowData: any): Promise<any>
|
|
2134
|
+
getMts100All(ids: string[] | string): Promise<any>
|
|
2135
|
+
setHubToggleX(subId: string, onoff: boolean): Promise<any>
|
|
2136
|
+
setHubMts100Mode(subId: string, mode: number): Promise<any>
|
|
2137
|
+
setHubMts100Temperature(subId: string, temp: any): Promise<any>
|
|
2138
|
+
setHubMts100Adjust(subId: string, adjustData: any): Promise<any>
|
|
2139
|
+
getMts100Adjust(ids: string[] | string): Promise<any>
|
|
2140
|
+
getMts100SuperCtl(ids: string[] | string): Promise<any>
|
|
2141
|
+
getMts100ScheduleB(ids: string[] | string): Promise<any>
|
|
2142
|
+
getMts100Config(ids: string[] | string): Promise<any>
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
/**
|
|
2146
|
+
* Base error class for all Meross errors.
|
|
2147
|
+
*
|
|
2148
|
+
* All library-specific errors extend this class to enable instanceof checks
|
|
2149
|
+
* and consistent error handling throughout the library.
|
|
2150
|
+
*/
|
|
2151
|
+
export class MerossError extends Error {
|
|
2152
|
+
/** API error code (if available) */
|
|
2153
|
+
errorCode: number | null
|
|
2154
|
+
constructor(message: string, errorCode?: number | null)
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
/**
|
|
2158
|
+
* HTTP API error.
|
|
2159
|
+
*
|
|
2160
|
+
* Thrown when an HTTP request to the Meross API fails or returns an error response.
|
|
2161
|
+
*/
|
|
2162
|
+
export class HttpApiError extends MerossError {
|
|
2163
|
+
/** HTTP status code (if available) */
|
|
2164
|
+
httpStatusCode: number | null
|
|
2165
|
+
constructor(message?: string, errorCode?: number | null, httpStatusCode?: number | null)
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
/**
|
|
2169
|
+
* Authentication error.
|
|
2170
|
+
*
|
|
2171
|
+
* Thrown when authentication fails due to invalid credentials or account issues.
|
|
2172
|
+
*/
|
|
2173
|
+
export class AuthenticationError extends MerossError {
|
|
2174
|
+
constructor(message?: string, errorCode?: number)
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
/**
|
|
2178
|
+
* MFA required error.
|
|
2179
|
+
*
|
|
2180
|
+
* Thrown when multi-factor authentication is required but not provided.
|
|
2181
|
+
*/
|
|
2182
|
+
export class MFARequiredError extends AuthenticationError {
|
|
2183
|
+
constructor(message?: string)
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
/**
|
|
2187
|
+
* Missing MFA error.
|
|
2188
|
+
*
|
|
2189
|
+
* Thrown when MFA is required but the code was not provided.
|
|
2190
|
+
*/
|
|
2191
|
+
export class MissingMFAError extends MFARequiredError {
|
|
2192
|
+
constructor(message?: string)
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
/**
|
|
2196
|
+
* Wrong MFA error.
|
|
2197
|
+
*
|
|
2198
|
+
* Thrown when an incorrect MFA code is provided.
|
|
2199
|
+
*/
|
|
2200
|
+
export class WrongMFAError extends AuthenticationError {
|
|
2201
|
+
constructor(message?: string)
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
/**
|
|
2205
|
+
* Token expired error.
|
|
2206
|
+
*
|
|
2207
|
+
* Thrown when the authentication token has expired and needs to be refreshed.
|
|
2208
|
+
*/
|
|
2209
|
+
export class TokenExpiredError extends MerossError {
|
|
2210
|
+
constructor(message?: string, errorCode?: number)
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
/**
|
|
2214
|
+
* Too many tokens error.
|
|
2215
|
+
*
|
|
2216
|
+
* Thrown when the maximum number of active tokens has been reached.
|
|
2217
|
+
*/
|
|
2218
|
+
export class TooManyTokensError extends MerossError {
|
|
2219
|
+
constructor(message?: string)
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* Unauthorized error.
|
|
2224
|
+
*
|
|
2225
|
+
* Thrown when authentication is required but not provided or invalid.
|
|
2226
|
+
*/
|
|
2227
|
+
export class UnauthorizedError extends HttpApiError {
|
|
2228
|
+
constructor(message?: string, errorCode?: number | null, httpStatusCode?: number)
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
/**
|
|
2232
|
+
* Bad domain error.
|
|
2233
|
+
*
|
|
2234
|
+
* Thrown when the API or MQTT domain is incorrect or unreachable.
|
|
2235
|
+
*/
|
|
2236
|
+
export class BadDomainError extends MerossError {
|
|
2237
|
+
/** API domain that failed */
|
|
2238
|
+
apiDomain: string | null
|
|
2239
|
+
/** MQTT domain that failed */
|
|
2240
|
+
mqttDomain: string | null
|
|
2241
|
+
constructor(message?: string, apiDomain?: string | null, mqttDomain?: string | null)
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
/**
|
|
2245
|
+
* API limit reached error.
|
|
2246
|
+
*
|
|
2247
|
+
* Thrown when the API rate limit has been exceeded.
|
|
2248
|
+
*/
|
|
2249
|
+
export class ApiLimitReachedError extends MerossError {
|
|
2250
|
+
constructor(message?: string)
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
/**
|
|
2254
|
+
* Resource access denied error.
|
|
2255
|
+
*
|
|
2256
|
+
* Thrown when access to a resource is denied due to insufficient permissions.
|
|
2257
|
+
*/
|
|
2258
|
+
export class ResourceAccessDeniedError extends MerossError {
|
|
2259
|
+
constructor(message?: string)
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
/**
|
|
2263
|
+
* Command timeout error.
|
|
2264
|
+
*
|
|
2265
|
+
* Thrown when a device command doesn't receive a response within the timeout period.
|
|
2266
|
+
*/
|
|
2267
|
+
export class CommandTimeoutError extends MerossError {
|
|
2268
|
+
/** UUID of the device that timed out */
|
|
2269
|
+
deviceUuid: string | null
|
|
2270
|
+
/** Timeout duration in milliseconds */
|
|
2271
|
+
timeout: number | null
|
|
2272
|
+
/** Command information */
|
|
2273
|
+
command: any
|
|
2274
|
+
constructor(message?: string, deviceUuid?: string | null, timeout?: number | null, command?: any)
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
/**
|
|
2278
|
+
* Command error.
|
|
2279
|
+
*
|
|
2280
|
+
* Thrown when a device command fails and the device returns an error response.
|
|
2281
|
+
*/
|
|
2282
|
+
export class CommandError extends MerossError {
|
|
2283
|
+
/** Error payload from device response */
|
|
2284
|
+
errorPayload: any
|
|
2285
|
+
/** UUID of the device that returned the error */
|
|
2286
|
+
deviceUuid: string | null
|
|
2287
|
+
constructor(message?: string, errorPayload?: any, deviceUuid?: string | null)
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
/**
|
|
2291
|
+
* MQTT error.
|
|
2292
|
+
*
|
|
2293
|
+
* Thrown when MQTT connection or communication fails.
|
|
2294
|
+
*/
|
|
2295
|
+
export class MqttError extends MerossError {
|
|
2296
|
+
/** MQTT topic related to the error */
|
|
2297
|
+
topic: string | null
|
|
2298
|
+
/** MQTT message related to the error */
|
|
2299
|
+
mqttMessage: any
|
|
2300
|
+
constructor(message?: string, topic?: string | null, mqttMessage?: any)
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
/**
|
|
2304
|
+
* Unconnected error.
|
|
2305
|
+
*
|
|
2306
|
+
* Thrown when attempting to send a command to a device that is not connected.
|
|
2307
|
+
*/
|
|
2308
|
+
export class UnconnectedError extends MerossError {
|
|
2309
|
+
/** UUID of the device that is not connected */
|
|
2310
|
+
deviceUuid: string | null
|
|
2311
|
+
constructor(message?: string, deviceUuid?: string | null)
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* Unknown device type error.
|
|
2316
|
+
*
|
|
2317
|
+
* Thrown when a device operation is attempted on a device type that doesn't support it.
|
|
2318
|
+
*/
|
|
2319
|
+
export class UnknownDeviceTypeError extends MerossError {
|
|
2320
|
+
/** Device type that is unsupported */
|
|
2321
|
+
deviceType: string | null
|
|
2322
|
+
constructor(message?: string, deviceType?: string | null)
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
/**
|
|
2326
|
+
* Maps error codes to appropriate error classes.
|
|
2327
|
+
*
|
|
2328
|
+
* Converts API error codes into specific error class instances based on the
|
|
2329
|
+
* error code value and context.
|
|
2330
|
+
*
|
|
2331
|
+
* @param errorCode - The error code from API response
|
|
2332
|
+
* @param context - Additional context (info, deviceUuid, httpStatusCode, etc.)
|
|
2333
|
+
* @returns Appropriate error instance
|
|
2334
|
+
*/
|
|
2335
|
+
export function mapErrorCodeToError(errorCode: number, context?: {
|
|
2336
|
+
info?: string
|
|
2337
|
+
deviceUuid?: string
|
|
2338
|
+
httpStatusCode?: number
|
|
2339
|
+
apiDomain?: string
|
|
2340
|
+
mqttDomain?: string
|
|
2341
|
+
}): MerossError
|
|
2342
|
+
|
|
2343
|
+
export default MerossManager
|
|
2344
|
+
}
|