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.
Files changed (99) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +153 -0
  4. package/index.d.ts +2344 -0
  5. package/index.js +131 -0
  6. package/lib/controller/device.js +1317 -0
  7. package/lib/controller/features/alarm-feature.js +89 -0
  8. package/lib/controller/features/child-lock-feature.js +61 -0
  9. package/lib/controller/features/config-feature.js +54 -0
  10. package/lib/controller/features/consumption-feature.js +210 -0
  11. package/lib/controller/features/control-feature.js +62 -0
  12. package/lib/controller/features/diffuser-feature.js +411 -0
  13. package/lib/controller/features/digest-timer-feature.js +22 -0
  14. package/lib/controller/features/digest-trigger-feature.js +22 -0
  15. package/lib/controller/features/dnd-feature.js +79 -0
  16. package/lib/controller/features/electricity-feature.js +144 -0
  17. package/lib/controller/features/encryption-feature.js +259 -0
  18. package/lib/controller/features/garage-feature.js +337 -0
  19. package/lib/controller/features/hub-feature.js +687 -0
  20. package/lib/controller/features/light-feature.js +408 -0
  21. package/lib/controller/features/presence-sensor-feature.js +297 -0
  22. package/lib/controller/features/roller-shutter-feature.js +456 -0
  23. package/lib/controller/features/runtime-feature.js +74 -0
  24. package/lib/controller/features/screen-feature.js +67 -0
  25. package/lib/controller/features/sensor-history-feature.js +47 -0
  26. package/lib/controller/features/smoke-config-feature.js +50 -0
  27. package/lib/controller/features/spray-feature.js +166 -0
  28. package/lib/controller/features/system-feature.js +269 -0
  29. package/lib/controller/features/temp-unit-feature.js +55 -0
  30. package/lib/controller/features/thermostat-feature.js +804 -0
  31. package/lib/controller/features/timer-feature.js +507 -0
  32. package/lib/controller/features/toggle-feature.js +223 -0
  33. package/lib/controller/features/trigger-feature.js +333 -0
  34. package/lib/controller/hub-device.js +185 -0
  35. package/lib/controller/subdevice.js +1537 -0
  36. package/lib/device-factory.js +463 -0
  37. package/lib/error-budget.js +138 -0
  38. package/lib/http-api.js +766 -0
  39. package/lib/manager.js +1609 -0
  40. package/lib/model/channel-info.js +79 -0
  41. package/lib/model/constants.js +119 -0
  42. package/lib/model/enums.js +819 -0
  43. package/lib/model/exception.js +363 -0
  44. package/lib/model/http/device.js +215 -0
  45. package/lib/model/http/error-codes.js +121 -0
  46. package/lib/model/http/exception.js +151 -0
  47. package/lib/model/http/subdevice.js +133 -0
  48. package/lib/model/push/alarm.js +112 -0
  49. package/lib/model/push/bind.js +97 -0
  50. package/lib/model/push/common.js +282 -0
  51. package/lib/model/push/diffuser-light.js +100 -0
  52. package/lib/model/push/diffuser-spray.js +83 -0
  53. package/lib/model/push/factory.js +229 -0
  54. package/lib/model/push/generic.js +115 -0
  55. package/lib/model/push/hub-battery.js +59 -0
  56. package/lib/model/push/hub-mts100-all.js +64 -0
  57. package/lib/model/push/hub-mts100-mode.js +59 -0
  58. package/lib/model/push/hub-mts100-temperature.js +62 -0
  59. package/lib/model/push/hub-online.js +59 -0
  60. package/lib/model/push/hub-sensor-alert.js +61 -0
  61. package/lib/model/push/hub-sensor-all.js +59 -0
  62. package/lib/model/push/hub-sensor-smoke.js +110 -0
  63. package/lib/model/push/hub-sensor-temphum.js +62 -0
  64. package/lib/model/push/hub-subdevicelist.js +50 -0
  65. package/lib/model/push/hub-togglex.js +60 -0
  66. package/lib/model/push/index.js +81 -0
  67. package/lib/model/push/online.js +53 -0
  68. package/lib/model/push/presence-study.js +61 -0
  69. package/lib/model/push/sensor-latestx.js +106 -0
  70. package/lib/model/push/timerx.js +63 -0
  71. package/lib/model/push/togglex.js +78 -0
  72. package/lib/model/push/triggerx.js +62 -0
  73. package/lib/model/push/unbind.js +34 -0
  74. package/lib/model/push/water-leak.js +107 -0
  75. package/lib/model/states/diffuser-light-state.js +119 -0
  76. package/lib/model/states/diffuser-spray-state.js +58 -0
  77. package/lib/model/states/garage-door-state.js +71 -0
  78. package/lib/model/states/index.js +38 -0
  79. package/lib/model/states/light-state.js +134 -0
  80. package/lib/model/states/presence-sensor-state.js +239 -0
  81. package/lib/model/states/roller-shutter-state.js +82 -0
  82. package/lib/model/states/spray-state.js +58 -0
  83. package/lib/model/states/thermostat-state.js +297 -0
  84. package/lib/model/states/timer-state.js +192 -0
  85. package/lib/model/states/toggle-state.js +105 -0
  86. package/lib/model/states/trigger-state.js +155 -0
  87. package/lib/subscription.js +587 -0
  88. package/lib/utilities/conversion.js +62 -0
  89. package/lib/utilities/debug.js +165 -0
  90. package/lib/utilities/mqtt.js +152 -0
  91. package/lib/utilities/network.js +53 -0
  92. package/lib/utilities/options.js +64 -0
  93. package/lib/utilities/request-queue.js +161 -0
  94. package/lib/utilities/ssid.js +37 -0
  95. package/lib/utilities/state-changes.js +66 -0
  96. package/lib/utilities/stats.js +687 -0
  97. package/lib/utilities/timer.js +310 -0
  98. package/lib/utilities/trigger.js +286 -0
  99. package/package.json +73 -0
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Represents the state of a timer configuration.
5
+ *
6
+ * Encapsulates state information for device timer configurations. Timers can be used
7
+ * to schedule device actions at specific times or intervals. State instances are
8
+ * managed by device controllers and updated automatically when device responses or
9
+ * push notifications are received.
10
+ *
11
+ * @class
12
+ * @example
13
+ * const timerState = device.getCachedTimerState(timerId);
14
+ * if (timerState) {
15
+ * console.log('Timer enabled:', timerState.enable);
16
+ * console.log('Timer type:', timerState.type);
17
+ * console.log('Scheduled time:', timerState.time);
18
+ * }
19
+ */
20
+ class TimerState {
21
+ /**
22
+ * Creates a new TimerState instance.
23
+ *
24
+ * @param {Object} [state=null] - Initial state object
25
+ * @param {string|number} [state.id] - Timer identifier
26
+ * @param {number} [state.channel] - Channel number
27
+ * @param {number} [state.week] - Weekday mask (bitmask for days of week)
28
+ * @param {number} [state.time] - Time value (minutes since midnight or timestamp)
29
+ * @param {number} [state.enable] - Enabled state (0=disabled, 1=enabled)
30
+ * @param {string} [state.alias] - Timer alias/name
31
+ * @param {number} [state.type] - Timer type (from TimerType enum)
32
+ * @param {number} [state.duration] - Duration value (for countdown timers)
33
+ * @param {number} [state.sunOffset] - Sunrise/sunset offset (for sun-based timers)
34
+ * @param {number} [state.createTime] - Creation timestamp
35
+ * @param {Object} [state.extend] - Extended configuration data
36
+ */
37
+ constructor(state = null) {
38
+ this._state = state || {};
39
+ }
40
+
41
+ /**
42
+ * Updates the state with new data.
43
+ *
44
+ * Merges new state data into the existing state using Object.assign to preserve
45
+ * properties not included in the update. Called automatically by device controllers
46
+ * when state updates are received from device responses or push notifications.
47
+ *
48
+ * @param {Object} state - New state data to merge
49
+ */
50
+ update(state) {
51
+ if (state) {
52
+ Object.assign(this._state, state);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Gets the timer identifier.
58
+ *
59
+ * @returns {string|number|undefined} Timer ID or undefined if not available
60
+ */
61
+ get id() {
62
+ return this._state.id;
63
+ }
64
+
65
+ /**
66
+ * Gets the channel number.
67
+ *
68
+ * @returns {number|undefined} Channel number or undefined if not available
69
+ */
70
+ get channel() {
71
+ const { channel } = this._state;
72
+ if (channel === undefined || channel === null) {return undefined;}
73
+ return channel;
74
+ }
75
+
76
+ /**
77
+ * Gets the weekday mask.
78
+ *
79
+ * Bitmask representing which days of the week the timer is active. Use bitwise
80
+ * operations to check for specific days.
81
+ *
82
+ * @returns {number|undefined} Weekday mask or undefined if not available
83
+ */
84
+ get week() {
85
+ const { week } = this._state;
86
+ if (week === undefined || week === null) {return undefined;}
87
+ return week;
88
+ }
89
+
90
+ /**
91
+ * Gets the time value.
92
+ *
93
+ * Interpretation depends on timer type: for daily timers it's minutes since
94
+ * midnight, for other types it may be a Unix timestamp.
95
+ *
96
+ * @returns {number|undefined} Time value (minutes since midnight or timestamp) or undefined if not available
97
+ */
98
+ get time() {
99
+ const { time } = this._state;
100
+ if (time === undefined || time === null) {return undefined;}
101
+ return time;
102
+ }
103
+
104
+ /**
105
+ * Gets whether the timer is enabled.
106
+ *
107
+ * Converts the device's numeric enabled state (0 or 1) to a boolean for easier
108
+ * conditional logic in application code.
109
+ *
110
+ * @returns {boolean|undefined} True if enabled, false if disabled, undefined if state not available
111
+ */
112
+ get enable() {
113
+ const { enable } = this._state;
114
+ if (enable === undefined || enable === null) {return undefined;}
115
+ return enable === 1;
116
+ }
117
+
118
+ /**
119
+ * Gets the timer alias/name.
120
+ *
121
+ * @returns {string|undefined} Timer alias or undefined if not available
122
+ */
123
+ get alias() {
124
+ return this._state.alias;
125
+ }
126
+
127
+ /**
128
+ * Gets the timer type.
129
+ *
130
+ * @returns {number|undefined} Timer type value or undefined if not available
131
+ * @see {@link module:lib/enums.TimerType} for type constants
132
+ */
133
+ get type() {
134
+ const { type } = this._state;
135
+ if (type === undefined || type === null) {return undefined;}
136
+ return type;
137
+ }
138
+
139
+ /**
140
+ * Gets the duration value.
141
+ *
142
+ * Specifies how long a countdown timer should run. Only relevant for countdown
143
+ * timer types.
144
+ *
145
+ * @returns {number|undefined} Duration value or undefined if not available
146
+ */
147
+ get duration() {
148
+ const { duration } = this._state;
149
+ if (duration === undefined || duration === null) {return undefined;}
150
+ return duration;
151
+ }
152
+
153
+ /**
154
+ * Gets the sunrise/sunset offset.
155
+ *
156
+ * Specifies the offset in minutes from sunrise or sunset for sun-based timers.
157
+ * Only relevant for timer types that use solar calculations.
158
+ *
159
+ * @returns {number|undefined} Sun offset value in minutes or undefined if not available
160
+ */
161
+ get sunOffset() {
162
+ const { sunOffset } = this._state;
163
+ if (sunOffset === undefined || sunOffset === null) {return undefined;}
164
+ return sunOffset;
165
+ }
166
+
167
+ /**
168
+ * Gets the creation timestamp.
169
+ *
170
+ * @returns {number|undefined} Creation timestamp or undefined if not available
171
+ */
172
+ get createTime() {
173
+ const { createTime } = this._state;
174
+ if (createTime === undefined || createTime === null) {return undefined;}
175
+ return createTime;
176
+ }
177
+
178
+ /**
179
+ * Gets the extended configuration data.
180
+ *
181
+ * Returns additional timer configuration that may not be covered by standard
182
+ * properties. Structure varies by device and timer type.
183
+ *
184
+ * @returns {Object|undefined} Extended configuration object or undefined if not available
185
+ */
186
+ get extend() {
187
+ return this._state.extend;
188
+ }
189
+ }
190
+
191
+ module.exports = TimerState;
192
+
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Represents the toggle (on/off) state of a device channel.
5
+ *
6
+ * Encapsulates state information for toggle devices (smart plugs, switches, etc.).
7
+ * State instances are managed by device controllers and updated automatically when
8
+ * device responses or push notifications are received.
9
+ *
10
+ * @class
11
+ * @example
12
+ * const toggleState = device.getCachedToggleState(0);
13
+ * if (toggleState && toggleState.isOn) {
14
+ * console.log('Device is on');
15
+ * }
16
+ */
17
+ class ToggleState {
18
+ /**
19
+ * Creates a new ToggleState instance.
20
+ *
21
+ * @param {Object} [state=null] - Initial state object
22
+ * @param {number} [state.onoff] - On/off state (0=off, 1=on)
23
+ * @param {number} [state.channel] - Channel number
24
+ * @param {number} [state.lmTime] - Last modified timestamp
25
+ * @param {number} [state.entity] - Entity identifier
26
+ */
27
+ constructor(state = null) {
28
+ this._state = state || {};
29
+ }
30
+
31
+ /**
32
+ * Updates the state with new data
33
+ *
34
+ * Merges new state data into the existing state. Called automatically by the device
35
+ * when state updates are received.
36
+ *
37
+ * @param {Object} state - New state data to merge
38
+ */
39
+ update(state) {
40
+ if (state) {
41
+ Object.assign(this._state, state);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Gets whether the device is on (as boolean)
47
+ *
48
+ * @returns {boolean|undefined} True if on, false if off, undefined if state not available
49
+ */
50
+ get isOn() {
51
+ const { onoff } = this._state;
52
+ if (onoff === undefined || onoff === null) {return undefined;}
53
+ return onoff === 1;
54
+ }
55
+
56
+ /**
57
+ * Gets the raw on/off state value.
58
+ *
59
+ * Returns the numeric on/off state as stored by the device. Use this when you
60
+ * need the exact format used in device communication protocols.
61
+ *
62
+ * @returns {number|undefined} 0 if off, 1 if on, undefined if not available
63
+ */
64
+ get onoff() {
65
+ const { onoff } = this._state;
66
+ if (onoff === undefined || onoff === null) {return undefined;}
67
+ return onoff;
68
+ }
69
+
70
+ /**
71
+ * Gets the channel number.
72
+ *
73
+ * @returns {number|undefined} Channel number or undefined if not available
74
+ */
75
+ get channel() {
76
+ const { channel } = this._state;
77
+ if (channel === undefined || channel === null) {return undefined;}
78
+ return channel;
79
+ }
80
+
81
+ /**
82
+ * Gets the last modified timestamp.
83
+ *
84
+ * @returns {number|undefined} Timestamp or undefined if not available
85
+ */
86
+ get lmTime() {
87
+ const { lmTime } = this._state;
88
+ if (lmTime === undefined || lmTime === null) {return undefined;}
89
+ return lmTime;
90
+ }
91
+
92
+ /**
93
+ * Gets the entity identifier.
94
+ *
95
+ * @returns {number|undefined} Entity ID or undefined if not available
96
+ */
97
+ get entity() {
98
+ const { entity } = this._state;
99
+ if (entity === undefined || entity === null) {return undefined;}
100
+ return entity;
101
+ }
102
+ }
103
+
104
+ module.exports = ToggleState;
105
+
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Represents the state of a trigger configuration.
5
+ *
6
+ * Encapsulates state information for device trigger configurations. Triggers can be
7
+ * used to create automation rules that respond to device events. State instances are
8
+ * managed by device controllers and updated automatically when device responses or
9
+ * push notifications are received.
10
+ *
11
+ * @class
12
+ * @example
13
+ * const triggerState = device.getCachedTriggerState(triggerId);
14
+ * if (triggerState) {
15
+ * console.log('Trigger enabled:', triggerState.enable);
16
+ * console.log('Trigger type:', triggerState.type);
17
+ * console.log('Rule duration:', triggerState.ruleDuration);
18
+ * }
19
+ */
20
+ class TriggerState {
21
+ /**
22
+ * Creates a new TriggerState instance.
23
+ *
24
+ * @param {Object} [state=null] - Initial state object
25
+ * @param {string|number} [state.id] - Trigger identifier
26
+ * @param {number} [state.channel] - Channel number
27
+ * @param {string} [state.alias] - Trigger alias/name
28
+ * @param {number} [state.enable] - Enabled state (0=disabled, 1=enabled)
29
+ * @param {number} [state.type] - Trigger type (from TriggerType enum)
30
+ * @param {number} [state.createTime] - Creation timestamp
31
+ * @param {Object} [state.rule] - Rule configuration object
32
+ * @param {number} [state.rule.duration] - Rule duration value
33
+ * @param {number} [state.rule.week] - Rule weekday mask
34
+ */
35
+ constructor(state = null) {
36
+ this._state = state || {};
37
+ }
38
+
39
+ /**
40
+ * Updates the state with new data
41
+ *
42
+ * Merges new state data into the existing state. Called automatically by the device
43
+ * when state updates are received.
44
+ *
45
+ * @param {Object} state - New state data to merge
46
+ */
47
+ update(state) {
48
+ if (state) {
49
+ Object.assign(this._state, state);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Gets the trigger identifier.
55
+ *
56
+ * @returns {string|number|undefined} Trigger ID or undefined if not available
57
+ */
58
+ get id() {
59
+ return this._state.id;
60
+ }
61
+
62
+ /**
63
+ * Gets the channel number.
64
+ *
65
+ * @returns {number|undefined} Channel number or undefined if not available
66
+ */
67
+ get channel() {
68
+ const { channel } = this._state;
69
+ if (channel === undefined || channel === null) {return undefined;}
70
+ return channel;
71
+ }
72
+
73
+ /**
74
+ * Gets the trigger alias/name.
75
+ *
76
+ * @returns {string|undefined} Trigger alias or undefined if not available
77
+ */
78
+ get alias() {
79
+ return this._state.alias;
80
+ }
81
+
82
+ /**
83
+ * Gets whether the trigger is enabled.
84
+ *
85
+ * Converts the device's numeric enabled state (0 or 1) to a boolean for easier
86
+ * conditional logic in application code.
87
+ *
88
+ * @returns {boolean|undefined} True if enabled, false if disabled, undefined if state not available
89
+ */
90
+ get enable() {
91
+ const { enable } = this._state;
92
+ if (enable === undefined || enable === null) {return undefined;}
93
+ return enable === 1;
94
+ }
95
+
96
+ /**
97
+ * Gets the trigger type.
98
+ *
99
+ * @returns {number|undefined} Trigger type value or undefined if not available
100
+ * @see {@link module:lib/enums.TriggerType} for type constants
101
+ */
102
+ get type() {
103
+ const { type } = this._state;
104
+ if (type === undefined || type === null) {return undefined;}
105
+ return type;
106
+ }
107
+
108
+ /**
109
+ * Gets the creation timestamp.
110
+ *
111
+ * @returns {number|undefined} Creation timestamp or undefined if not available
112
+ */
113
+ get createTime() {
114
+ const { createTime } = this._state;
115
+ if (createTime === undefined || createTime === null) {return undefined;}
116
+ return createTime;
117
+ }
118
+
119
+ /**
120
+ * Gets the rule configuration object
121
+ *
122
+ * @returns {Object|undefined} Rule configuration object or undefined if not available
123
+ */
124
+ get rule() {
125
+ return this._state.rule;
126
+ }
127
+
128
+ /**
129
+ * Gets the rule duration value.
130
+ *
131
+ * @returns {number|undefined} Rule duration or undefined if not available
132
+ */
133
+ get ruleDuration() {
134
+ const { rule } = this._state;
135
+ if (!rule) {return undefined;}
136
+ return rule.duration;
137
+ }
138
+
139
+ /**
140
+ * Gets the rule weekday mask.
141
+ *
142
+ * Bitmask representing which days of the week the trigger rule is active. Use
143
+ * bitwise operations to check for specific days.
144
+ *
145
+ * @returns {number|undefined} Weekday mask or undefined if not available
146
+ */
147
+ get ruleWeek() {
148
+ const { rule } = this._state;
149
+ if (!rule) {return undefined;}
150
+ return rule.week;
151
+ }
152
+ }
153
+
154
+ module.exports = TriggerState;
155
+