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,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for hub temperature/humidity sensor updates.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a hub temperature/humidity sensor subdevice sends temperature or humidity
|
|
9
|
+
* readings. Routed to the appropriate subdevice by the hub device.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* hubDevice.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof HubSensorTempHumPushNotification) {
|
|
16
|
+
* const tempHumData = notification.tempHumData;
|
|
17
|
+
* tempHumData.forEach(sensor => {
|
|
18
|
+
* console.log('Temp/Hum sensor update:', sensor.id);
|
|
19
|
+
* console.log('Temperature:', sensor.temperature);
|
|
20
|
+
* console.log('Humidity:', sensor.humidity);
|
|
21
|
+
* });
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
class HubSensorTempHumPushNotification extends GenericPushNotification {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new HubSensorTempHumPushNotification instance.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} originatingDeviceUuid - UUID of the hub device that sent the notification
|
|
30
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
31
|
+
* @param {Object|Array} [rawData.tempHum] - Temperature/humidity data (single object or array)
|
|
32
|
+
* @param {string|number} [rawData.tempHum.id] - Subdevice ID
|
|
33
|
+
* @param {number} [rawData.tempHum.temperature] - Temperature reading
|
|
34
|
+
* @param {number} [rawData.tempHum.humidity] - Humidity reading
|
|
35
|
+
*/
|
|
36
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
37
|
+
super('Appliance.Hub.Sensor.TempHum', originatingDeviceUuid, rawData);
|
|
38
|
+
|
|
39
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
40
|
+
const tempHumRaw = rawData?.tempHum;
|
|
41
|
+
const tempHum = GenericPushNotification.normalizeToArray(tempHumRaw);
|
|
42
|
+
|
|
43
|
+
// Update rawData so routing logic receives normalized structure
|
|
44
|
+
if (rawData && tempHumRaw !== tempHum) {
|
|
45
|
+
rawData.tempHum = tempHum;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this._tempHumData = tempHum;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Gets the temperature/humidity data array.
|
|
53
|
+
*
|
|
54
|
+
* @returns {Array} Array of temperature/humidity objects (empty array if no data)
|
|
55
|
+
*/
|
|
56
|
+
get tempHumData() {
|
|
57
|
+
return this._tempHumData;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = HubSensorTempHumPushNotification;
|
|
62
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for hub subdevice list updates.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a hub's subdevice list changes (e.g., subdevice added, removed, or updated).
|
|
9
|
+
* Contains the updated list of subdevices registered with the hub.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* hubDevice.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof HubSubdeviceListPushNotification) {
|
|
16
|
+
* const subdevices = notification.subdeviceListData;
|
|
17
|
+
* console.log('Subdevice list updated. Total subdevices:', subdevices.length);
|
|
18
|
+
* subdevices.forEach(subdevice => {
|
|
19
|
+
* console.log('Subdevice:', subdevice.id, subdevice.type);
|
|
20
|
+
* });
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
class HubSubdeviceListPushNotification extends GenericPushNotification {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new HubSubdeviceListPushNotification instance.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} originatingDeviceUuid - UUID of the hub device that sent the notification
|
|
29
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
30
|
+
* @param {Object|Array} [rawData.subdeviceList] - Subdevice list data
|
|
31
|
+
* @param {Array} [rawData.subdeviceList.subdevice] - Array of subdevice objects (if nested structure)
|
|
32
|
+
*/
|
|
33
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
34
|
+
super('Appliance.Hub.SubdeviceList', originatingDeviceUuid, rawData);
|
|
35
|
+
|
|
36
|
+
this._subdeviceListData = rawData?.subdeviceList || rawData?.subdeviceList?.subdevice || [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the subdevice list data array.
|
|
41
|
+
*
|
|
42
|
+
* @returns {Array} Array of subdevice objects (empty array if no data)
|
|
43
|
+
*/
|
|
44
|
+
get subdeviceListData() {
|
|
45
|
+
return this._subdeviceListData;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = HubSubdeviceListPushNotification;
|
|
50
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for hub subdevice toggle (on/off) state changes.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a hub subdevice's toggle state changes.
|
|
9
|
+
* Routed to the appropriate subdevice by the hub device.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* hubDevice.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof HubToggleXPushNotification) {
|
|
16
|
+
* const toggleData = notification.togglexData;
|
|
17
|
+
* toggleData.forEach(toggle => {
|
|
18
|
+
* console.log(`Subdevice ${toggle.id} channel ${toggle.channel} is now ${toggle.onoff === 1 ? 'on' : 'off'}`);
|
|
19
|
+
* });
|
|
20
|
+
* }
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
class HubToggleXPushNotification extends GenericPushNotification {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new HubToggleXPushNotification instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} originatingDeviceUuid - UUID of the hub device that sent the notification
|
|
28
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
29
|
+
* @param {Object|Array} [rawData.togglex] - Toggle state data (single object or array)
|
|
30
|
+
* @param {string|number} [rawData.togglex.id] - Subdevice ID
|
|
31
|
+
* @param {number} [rawData.togglex.channel] - Channel number
|
|
32
|
+
* @param {number} [rawData.togglex.onoff] - On/off state (0=off, 1=on)
|
|
33
|
+
*/
|
|
34
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
35
|
+
super('Appliance.Hub.ToggleX', originatingDeviceUuid, rawData);
|
|
36
|
+
|
|
37
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
38
|
+
const togglexRaw = rawData?.togglex;
|
|
39
|
+
const togglex = GenericPushNotification.normalizeToArray(togglexRaw);
|
|
40
|
+
|
|
41
|
+
// Update rawData so routing logic receives normalized structure
|
|
42
|
+
if (rawData && togglexRaw !== togglex) {
|
|
43
|
+
rawData.togglex = togglex;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this._togglexData = togglex;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Gets the toggle state data array.
|
|
51
|
+
*
|
|
52
|
+
* @returns {Array} Array of toggle state objects (empty array if no data)
|
|
53
|
+
*/
|
|
54
|
+
get togglexData() {
|
|
55
|
+
return this._togglexData;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = HubToggleXPushNotification;
|
|
60
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/model/push
|
|
3
|
+
* @description
|
|
4
|
+
* Push notification classes for handling real-time updates from Meross devices.
|
|
5
|
+
*
|
|
6
|
+
* Provides classes for parsing and handling various types of push notifications sent by
|
|
7
|
+
* Meross devices via MQTT. These notifications enable real-time event handling without
|
|
8
|
+
* polling, covering device state changes, alarms, hub subdevice updates, and configuration
|
|
9
|
+
* changes. Each notification type extends GenericPushNotification and provides type-specific
|
|
10
|
+
* data accessors and change extraction methods.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { parsePushNotification, ToggleXPushNotification } = require('./lib/model/push');
|
|
14
|
+
*
|
|
15
|
+
* device.on('pushNotification', (notification) => {
|
|
16
|
+
* if (notification instanceof ToggleXPushNotification) {
|
|
17
|
+
* console.log('Toggle state changed');
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
const GenericPushNotification = require('./generic');
|
|
25
|
+
const OnlinePushNotification = require('./online');
|
|
26
|
+
const AlarmPushNotification = require('./alarm');
|
|
27
|
+
const BindPushNotification = require('./bind');
|
|
28
|
+
const UnbindPushNotification = require('./unbind');
|
|
29
|
+
const WaterLeakPushNotification = require('./water-leak');
|
|
30
|
+
const HubOnlinePushNotification = require('./hub-online');
|
|
31
|
+
const HubToggleXPushNotification = require('./hub-togglex');
|
|
32
|
+
const HubBatteryPushNotification = require('./hub-battery');
|
|
33
|
+
const HubSensorAllPushNotification = require('./hub-sensor-all');
|
|
34
|
+
const HubSensorTempHumPushNotification = require('./hub-sensor-temphum');
|
|
35
|
+
const HubSensorAlertPushNotification = require('./hub-sensor-alert');
|
|
36
|
+
const HubSensorSmokePushNotification = require('./hub-sensor-smoke');
|
|
37
|
+
const HubMts100AllPushNotification = require('./hub-mts100-all');
|
|
38
|
+
const HubMts100ModePushNotification = require('./hub-mts100-mode');
|
|
39
|
+
const HubMts100TemperaturePushNotification = require('./hub-mts100-temperature');
|
|
40
|
+
const HubSubdeviceListPushNotification = require('./hub-subdevicelist');
|
|
41
|
+
const SensorLatestXPushNotification = require('./sensor-latestx');
|
|
42
|
+
const TimerXPushNotification = require('./timerx');
|
|
43
|
+
const TriggerXPushNotification = require('./triggerx');
|
|
44
|
+
const ToggleXPushNotification = require('./togglex');
|
|
45
|
+
const PresenceStudyPushNotification = require('./presence-study');
|
|
46
|
+
const DiffuserLightPushNotification = require('./diffuser-light');
|
|
47
|
+
const DiffuserSprayPushNotification = require('./diffuser-spray');
|
|
48
|
+
const { HardwareInfo, FirmwareInfo, TimeInfo } = require('./common');
|
|
49
|
+
const { parsePushNotification } = require('./factory');
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
GenericPushNotification,
|
|
53
|
+
OnlinePushNotification,
|
|
54
|
+
AlarmPushNotification,
|
|
55
|
+
BindPushNotification,
|
|
56
|
+
UnbindPushNotification,
|
|
57
|
+
WaterLeakPushNotification,
|
|
58
|
+
HubOnlinePushNotification,
|
|
59
|
+
HubToggleXPushNotification,
|
|
60
|
+
HubBatteryPushNotification,
|
|
61
|
+
HubSensorAllPushNotification,
|
|
62
|
+
HubSensorTempHumPushNotification,
|
|
63
|
+
HubSensorAlertPushNotification,
|
|
64
|
+
HubSensorSmokePushNotification,
|
|
65
|
+
HubMts100AllPushNotification,
|
|
66
|
+
HubMts100ModePushNotification,
|
|
67
|
+
HubMts100TemperaturePushNotification,
|
|
68
|
+
HubSubdeviceListPushNotification,
|
|
69
|
+
SensorLatestXPushNotification,
|
|
70
|
+
TimerXPushNotification,
|
|
71
|
+
TriggerXPushNotification,
|
|
72
|
+
ToggleXPushNotification,
|
|
73
|
+
PresenceStudyPushNotification,
|
|
74
|
+
DiffuserLightPushNotification,
|
|
75
|
+
DiffuserSprayPushNotification,
|
|
76
|
+
HardwareInfo,
|
|
77
|
+
FirmwareInfo,
|
|
78
|
+
TimeInfo,
|
|
79
|
+
parsePushNotification
|
|
80
|
+
};
|
|
81
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for device online status changes.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a device's connection status changes (online, offline, or upgrade mode).
|
|
9
|
+
* Devices send this notification to report their connection state to the Meross cloud.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* device.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof OnlinePushNotification) {
|
|
16
|
+
* console.log('Device status changed:', notification.status);
|
|
17
|
+
* // status: 0=not online, 1=online, 2=offline, 3=upgrading
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
class OnlinePushNotification extends GenericPushNotification {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new OnlinePushNotification instance.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} originatingDeviceUuid - UUID of the device that sent the notification
|
|
26
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
27
|
+
* @param {Object} [rawData.online] - Online status data
|
|
28
|
+
* @param {number} [rawData.online.status] - Online status value (from OnlineStatus enum)
|
|
29
|
+
*/
|
|
30
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
31
|
+
super('Appliance.System.Online', originatingDeviceUuid, rawData);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gets the online status value.
|
|
36
|
+
*
|
|
37
|
+
* Explicitly checks for null/undefined to distinguish between missing data and
|
|
38
|
+
* a valid zero value (not online).
|
|
39
|
+
*
|
|
40
|
+
* @returns {number|undefined} Status value (0=not online, 1=online, 2=offline, 3=upgrading, -1=unknown) or undefined if not available
|
|
41
|
+
* @see {@link module:lib/enums.OnlineStatus} for status constants
|
|
42
|
+
*/
|
|
43
|
+
get status() {
|
|
44
|
+
const statusValue = this._rawData?.online?.status;
|
|
45
|
+
if (statusValue === undefined || statusValue === null) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return statusValue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = OnlinePushNotification;
|
|
53
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for presence sensor study/calibration status changes.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a presence sensor's study/calibration mode status changes (e.g., study mode
|
|
9
|
+
* started or stopped). Contains the updated study status for one or more channels.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* device.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof PresenceStudyPushNotification) {
|
|
16
|
+
* const studyData = notification.studyData;
|
|
17
|
+
* studyData.forEach(study => {
|
|
18
|
+
* console.log(`Channel ${study.channel} study status: ${study.status === 1 ? 'active' : 'inactive'}`);
|
|
19
|
+
* console.log(`Study value: ${study.value}`);
|
|
20
|
+
* });
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
class PresenceStudyPushNotification extends GenericPushNotification {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new PresenceStudyPushNotification instance.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} originatingDeviceUuid - UUID of the device that sent the notification
|
|
29
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
30
|
+
* @param {Object|Array} [rawData.study] - Study status data (single object or array)
|
|
31
|
+
* @param {number} [rawData.study.channel] - Channel number
|
|
32
|
+
* @param {number} [rawData.study.value] - Study mode value (typically 1-3)
|
|
33
|
+
* @param {number} [rawData.study.status] - Study status (0 = stop/inactive, 1 = start/active)
|
|
34
|
+
*/
|
|
35
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
36
|
+
super('Appliance.Control.Presence.Study', originatingDeviceUuid, rawData);
|
|
37
|
+
|
|
38
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
39
|
+
const studyRaw = rawData?.study;
|
|
40
|
+
const study = GenericPushNotification.normalizeToArray(studyRaw);
|
|
41
|
+
|
|
42
|
+
// Update rawData so routing logic receives normalized structure
|
|
43
|
+
if (rawData && studyRaw !== study) {
|
|
44
|
+
rawData.study = study;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this._studyData = study;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets the study status data array.
|
|
52
|
+
*
|
|
53
|
+
* @returns {Array} Array of study status objects (empty array if no data)
|
|
54
|
+
*/
|
|
55
|
+
get studyData() {
|
|
56
|
+
return this._studyData;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = PresenceStudyPushNotification;
|
|
61
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
const { PresenceState } = require('../enums');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Push notification for latest sensor readings (including lux/illuminance).
|
|
8
|
+
*
|
|
9
|
+
* Emitted when a hub sensor subdevice sends latest readings for temperature, humidity, and light.
|
|
10
|
+
* Routed to the appropriate subdevice by the hub device.
|
|
11
|
+
*
|
|
12
|
+
* @class
|
|
13
|
+
* @extends GenericPushNotification
|
|
14
|
+
* @example
|
|
15
|
+
* hubDevice.on('pushNotification', (notification) => {
|
|
16
|
+
* if (notification instanceof SensorLatestXPushNotification) {
|
|
17
|
+
* const latestData = notification.latestData;
|
|
18
|
+
* latestData.forEach(sensor => {
|
|
19
|
+
* console.log('Latest sensor readings:', sensor.subId);
|
|
20
|
+
* });
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
class SensorLatestXPushNotification extends GenericPushNotification {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new SensorLatestXPushNotification instance.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} originatingDeviceUuid - UUID of the hub device that sent the notification
|
|
29
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
30
|
+
* @param {Object|Array} [rawData.latest] - Latest sensor readings (single object or array)
|
|
31
|
+
* @param {string|number} [rawData.latest.subId] - Subdevice ID (note: uses subId, not id)
|
|
32
|
+
* @param {number} [rawData.latest.channel] - Channel number
|
|
33
|
+
* @param {Object} [rawData.latest.data] - Sensor data containing temp, humi, and light arrays
|
|
34
|
+
*/
|
|
35
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
36
|
+
super('Appliance.Control.Sensor.LatestX', originatingDeviceUuid, rawData);
|
|
37
|
+
|
|
38
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
39
|
+
const latestRaw = rawData?.latest;
|
|
40
|
+
const latest = GenericPushNotification.normalizeToArray(latestRaw);
|
|
41
|
+
|
|
42
|
+
// Update rawData so routing logic receives normalized structure
|
|
43
|
+
if (rawData && latestRaw !== latest) {
|
|
44
|
+
rawData.latest = latest;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this._latestData = latest;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets the latest sensor readings data array.
|
|
52
|
+
*
|
|
53
|
+
* @returns {Array} Array of latest sensor reading objects (empty array if no data)
|
|
54
|
+
*/
|
|
55
|
+
get latestData() {
|
|
56
|
+
return this._latestData;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Extracts presence sensor changes from this notification.
|
|
61
|
+
*
|
|
62
|
+
* Converts raw device data format (presence arrays, light arrays) to normalized change
|
|
63
|
+
* format used by subscription managers. Maps presence values to boolean isPresent and
|
|
64
|
+
* extracts distance, timestamp, and light readings.
|
|
65
|
+
*
|
|
66
|
+
* @returns {Object} Changes object with presence sensor data, e.g., { presence: { 0: {...} } }
|
|
67
|
+
*/
|
|
68
|
+
extractChanges() {
|
|
69
|
+
const changes = {};
|
|
70
|
+
if (!this._latestData || this._latestData.length === 0) {
|
|
71
|
+
return changes;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
changes.presence = {};
|
|
75
|
+
this._latestData.forEach(entry => {
|
|
76
|
+
if (!entry || !entry.data) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const channel = entry.channel !== undefined ? entry.channel : 0;
|
|
80
|
+
const presenceChange = {};
|
|
81
|
+
|
|
82
|
+
if (entry.data.presence && Array.isArray(entry.data.presence) && entry.data.presence.length > 0) {
|
|
83
|
+
const presenceData = entry.data.presence[0];
|
|
84
|
+
presenceChange.isPresent = presenceData.value === PresenceState.PRESENCE;
|
|
85
|
+
presenceChange.distance = presenceData.distance;
|
|
86
|
+
presenceChange.timestamp = presenceData.timestamp;
|
|
87
|
+
presenceChange.times = presenceData.times;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (entry.data.light && Array.isArray(entry.data.light) && entry.data.light.length > 0) {
|
|
91
|
+
const lightData = entry.data.light[0];
|
|
92
|
+
presenceChange.light = lightData.value;
|
|
93
|
+
presenceChange.lightTimestamp = lightData.timestamp;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (Object.keys(presenceChange).length > 0) {
|
|
97
|
+
changes.presence[channel] = presenceChange;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return changes;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = SensorLatestXPushNotification;
|
|
106
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for timer configuration changes.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a device's timer configuration changes (e.g., timer added, modified,
|
|
9
|
+
* deleted, or triggered). Contains the updated timer data.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* device.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof TimerXPushNotification) {
|
|
16
|
+
* const timerData = notification.timerxData;
|
|
17
|
+
* timerData.forEach(timer => {
|
|
18
|
+
* console.log('Timer updated:', timer.id, timer.enable === 1 ? 'enabled' : 'disabled');
|
|
19
|
+
* });
|
|
20
|
+
* }
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
class TimerXPushNotification extends GenericPushNotification {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new TimerXPushNotification instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} originatingDeviceUuid - UUID of the device that sent the notification
|
|
28
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
29
|
+
* @param {Object|Array} [rawData.timerx] - Timer data (single object or array)
|
|
30
|
+
* @param {string|number} [rawData.timerx.id] - Timer identifier
|
|
31
|
+
* @param {number} [rawData.timerx.channel] - Channel number
|
|
32
|
+
* @param {number} [rawData.timerx.enable] - Enabled state (0=disabled, 1=enabled)
|
|
33
|
+
* @param {number} [rawData.timerx.type] - Timer type
|
|
34
|
+
* @param {number} [rawData.timerx.time] - Time value
|
|
35
|
+
* @param {number} [rawData.timerx.week] - Weekday mask
|
|
36
|
+
*/
|
|
37
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
38
|
+
super('Appliance.Control.TimerX', originatingDeviceUuid, rawData);
|
|
39
|
+
|
|
40
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
41
|
+
const timerxRaw = rawData?.timerx;
|
|
42
|
+
const timerx = GenericPushNotification.normalizeToArray(timerxRaw);
|
|
43
|
+
|
|
44
|
+
// Update rawData so routing logic receives normalized structure
|
|
45
|
+
if (rawData && timerxRaw !== timerx) {
|
|
46
|
+
rawData.timerx = timerx;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this._timerxData = timerx;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Gets the timer data array.
|
|
54
|
+
*
|
|
55
|
+
* @returns {Array} Array of timer objects (empty array if no data)
|
|
56
|
+
*/
|
|
57
|
+
get timerxData() {
|
|
58
|
+
return this._timerxData;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = TimerXPushNotification;
|
|
63
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for toggle (on/off) state changes.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a device's toggle state changes (e.g., a smart plug is turned on or off).
|
|
9
|
+
* Contains the updated toggle state for one or more channels.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* device.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof ToggleXPushNotification) {
|
|
16
|
+
* const toggleData = notification.togglexData;
|
|
17
|
+
* toggleData.forEach(toggle => {
|
|
18
|
+
* console.log(`Channel ${toggle.channel} is now ${toggle.onoff === 1 ? 'on' : 'off'}`);
|
|
19
|
+
* });
|
|
20
|
+
* }
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
class ToggleXPushNotification extends GenericPushNotification {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new ToggleXPushNotification instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} originatingDeviceUuid - UUID of the device that sent the notification
|
|
28
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
29
|
+
* @param {Object|Array} [rawData.togglex] - Toggle state data (single object or array)
|
|
30
|
+
* @param {number} [rawData.togglex.channel] - Channel number
|
|
31
|
+
* @param {number} [rawData.togglex.onoff] - On/off state (0=off, 1=on)
|
|
32
|
+
*/
|
|
33
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
34
|
+
super('Appliance.Control.ToggleX', originatingDeviceUuid, rawData);
|
|
35
|
+
|
|
36
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
37
|
+
const togglexRaw = rawData?.togglex;
|
|
38
|
+
const togglex = GenericPushNotification.normalizeToArray(togglexRaw);
|
|
39
|
+
|
|
40
|
+
// Update rawData so routing logic receives normalized structure
|
|
41
|
+
if (rawData && togglexRaw !== togglex) {
|
|
42
|
+
rawData.togglex = togglex;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this._togglexData = togglex;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets the toggle state data array.
|
|
50
|
+
*
|
|
51
|
+
* @returns {Array} Array of toggle state objects (empty array if no data)
|
|
52
|
+
*/
|
|
53
|
+
get togglexData() {
|
|
54
|
+
return this._togglexData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Extracts toggle state changes from this notification.
|
|
59
|
+
*
|
|
60
|
+
* Converts raw device data format (onoff: 0/1) to normalized change format (boolean)
|
|
61
|
+
* used by subscription managers, keyed by channel number.
|
|
62
|
+
*
|
|
63
|
+
* @returns {Object} Changes object with toggle state, e.g., { toggle: { 0: true, 1: false } }
|
|
64
|
+
*/
|
|
65
|
+
extractChanges() {
|
|
66
|
+
const changes = {};
|
|
67
|
+
if (this._togglexData && this._togglexData.length > 0) {
|
|
68
|
+
changes.toggle = {};
|
|
69
|
+
this._togglexData.forEach(item => {
|
|
70
|
+
changes.toggle[item.channel] = item.onoff === 1;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return changes;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = ToggleXPushNotification;
|
|
78
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const GenericPushNotification = require('./generic');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Push notification for trigger configuration changes.
|
|
7
|
+
*
|
|
8
|
+
* Emitted when a device's trigger configuration changes (e.g., trigger added, modified,
|
|
9
|
+
* deleted, or activated). Contains the updated trigger data.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @extends GenericPushNotification
|
|
13
|
+
* @example
|
|
14
|
+
* device.on('pushNotification', (notification) => {
|
|
15
|
+
* if (notification instanceof TriggerXPushNotification) {
|
|
16
|
+
* const triggerData = notification.triggerxData;
|
|
17
|
+
* triggerData.forEach(trigger => {
|
|
18
|
+
* console.log('Trigger updated:', trigger.id, trigger.enable === 1 ? 'enabled' : 'disabled');
|
|
19
|
+
* });
|
|
20
|
+
* }
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
class TriggerXPushNotification extends GenericPushNotification {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new TriggerXPushNotification instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} originatingDeviceUuid - UUID of the device that sent the notification
|
|
28
|
+
* @param {Object} rawData - Raw notification data from the device
|
|
29
|
+
* @param {Object|Array} [rawData.triggerx] - Trigger data (single object or array)
|
|
30
|
+
* @param {string|number} [rawData.triggerx.id] - Trigger identifier
|
|
31
|
+
* @param {number} [rawData.triggerx.channel] - Channel number
|
|
32
|
+
* @param {number} [rawData.triggerx.enable] - Enabled state (0=disabled, 1=enabled)
|
|
33
|
+
* @param {number} [rawData.triggerx.type] - Trigger type
|
|
34
|
+
* @param {Object} [rawData.triggerx.rule] - Trigger rule configuration
|
|
35
|
+
*/
|
|
36
|
+
constructor(originatingDeviceUuid, rawData) {
|
|
37
|
+
super('Appliance.Control.TriggerX', originatingDeviceUuid, rawData);
|
|
38
|
+
|
|
39
|
+
// Devices may send single objects or arrays; normalize to array for consistent processing
|
|
40
|
+
const triggerxRaw = rawData?.triggerx;
|
|
41
|
+
const triggerx = GenericPushNotification.normalizeToArray(triggerxRaw);
|
|
42
|
+
|
|
43
|
+
// Update rawData so routing logic receives normalized structure
|
|
44
|
+
if (rawData && triggerxRaw !== triggerx) {
|
|
45
|
+
rawData.triggerx = triggerx;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this._triggerxData = triggerx;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Gets the trigger data array.
|
|
53
|
+
*
|
|
54
|
+
* @returns {Array} Array of trigger objects (empty array if no data)
|
|
55
|
+
*/
|
|
56
|
+
get triggerxData() {
|
|
57
|
+
return this._triggerxData;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = TriggerXPushNotification;
|
|
62
|
+
|