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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builds an object containing only the fields that have changed between old and new state values.
|
|
5
|
+
*
|
|
6
|
+
* This utility centralizes state change detection logic used across multiple feature update
|
|
7
|
+
* methods. It minimizes unnecessary API calls by only including fields that actually changed.
|
|
8
|
+
* Supports both simple value comparisons and deep comparisons for arrays and objects (like RGB tuples)
|
|
9
|
+
* that require structural comparison rather than reference equality.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object|undefined} oldValue - The previous state value object, or undefined if no previous state exists
|
|
12
|
+
* @param {Object} fieldValues - Object mapping field names to their new values (e.g., `{isOn: state.isOn, brightness: state.luminance}`)
|
|
13
|
+
* @param {Array<string>} [deepCompareFields=[]] - Array of field names that require deep comparison using JSON.stringify (e.g., `['rgb']`)
|
|
14
|
+
* @returns {Object} Object containing only the changed fields, or empty object if nothing changed
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Simple field comparison
|
|
18
|
+
* const oldValue = { isOn: true, mode: 1 };
|
|
19
|
+
* const fieldValues = { isOn: false, mode: 1 };
|
|
20
|
+
* const changes = buildStateChanges(oldValue, fieldValues);
|
|
21
|
+
* // Returns: { isOn: false }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Deep comparison for arrays/objects
|
|
25
|
+
* const oldValue = { rgb: [255, 0, 0], mode: 1 };
|
|
26
|
+
* const fieldValues = { rgb: [0, 255, 0], mode: 1 };
|
|
27
|
+
* const changes = buildStateChanges(oldValue, fieldValues, ['rgb']);
|
|
28
|
+
* // Returns: { rgb: [0, 255, 0] }
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // First time (oldValue is undefined) - all fields included
|
|
32
|
+
* const changes = buildStateChanges(undefined, { isOn: true, mode: 1 });
|
|
33
|
+
* // Returns: { isOn: true, mode: 1 }
|
|
34
|
+
*/
|
|
35
|
+
function buildStateChanges(oldValue, fieldValues, deepCompareFields = []) {
|
|
36
|
+
if (!fieldValues || typeof fieldValues !== 'object') {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const newValue = {};
|
|
41
|
+
|
|
42
|
+
for (const [fieldName, newFieldValue] of Object.entries(fieldValues)) {
|
|
43
|
+
if (oldValue === undefined) {
|
|
44
|
+
newValue[fieldName] = newFieldValue;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const oldFieldValue = oldValue[fieldName];
|
|
49
|
+
|
|
50
|
+
if (deepCompareFields.includes(fieldName)) {
|
|
51
|
+
if (JSON.stringify(oldFieldValue) !== JSON.stringify(newFieldValue)) {
|
|
52
|
+
newValue[fieldName] = newFieldValue;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
if (oldFieldValue !== newFieldValue) {
|
|
56
|
+
newValue[fieldName] = newFieldValue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return newValue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
buildStateChanges
|
|
66
|
+
};
|