homebridge-melcloud-control 3.10.0-beta.26 → 3.10.0-beta.28
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/config.schema.json +13 -33
- package/index.js +7 -7
- package/package.json +2 -2
- package/src/deviceata.js +31 -54
- package/src/deviceatw.js +31 -54
- package/src/deviceerv.js +31 -54
- package/src/impulsegenerator.js +18 -30
- package/src/mqtt.js +5 -5
- package/src/restful.js +10 -9
package/config.schema.json
CHANGED
|
@@ -1707,15 +1707,6 @@
|
|
|
1707
1707
|
"type": "boolean",
|
|
1708
1708
|
"default": false,
|
|
1709
1709
|
"description": "This enable RESTful server."
|
|
1710
|
-
},
|
|
1711
|
-
"debug": {
|
|
1712
|
-
"title": "Debug",
|
|
1713
|
-
"type": "boolean",
|
|
1714
|
-
"default": false,
|
|
1715
|
-
"description": "This enable debug mode for RESTFul.",
|
|
1716
|
-
"condition": {
|
|
1717
|
-
"functionBody": "return model.accounts[arrayIndices].restFul.enable === true;"
|
|
1718
|
-
}
|
|
1719
1710
|
}
|
|
1720
1711
|
}
|
|
1721
1712
|
},
|
|
@@ -1766,15 +1757,6 @@
|
|
|
1766
1757
|
"functionBody": "return model.accounts[arrayIndices].mqtt.enable === true;"
|
|
1767
1758
|
}
|
|
1768
1759
|
},
|
|
1769
|
-
"debug": {
|
|
1770
|
-
"title": "Debug",
|
|
1771
|
-
"type": "boolean",
|
|
1772
|
-
"default": false,
|
|
1773
|
-
"description": "This enable debug mode for MQTT.",
|
|
1774
|
-
"condition": {
|
|
1775
|
-
"functionBody": "return model.accounts[arrayIndices].mqtt.enable === true;"
|
|
1776
|
-
}
|
|
1777
|
-
},
|
|
1778
1760
|
"auth": {
|
|
1779
1761
|
"title": "Authorization",
|
|
1780
1762
|
"type": "object",
|
|
@@ -1872,7 +1854,7 @@
|
|
|
1872
1854
|
"accounts[].ataDevices[].refreshInterval"
|
|
1873
1855
|
],
|
|
1874
1856
|
"condition": {
|
|
1875
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode
|
|
1857
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
|
|
1876
1858
|
}
|
|
1877
1859
|
},
|
|
1878
1860
|
{
|
|
@@ -1886,7 +1868,7 @@
|
|
|
1886
1868
|
"accounts[].ataDevices[].temperatureSensorOutdoor"
|
|
1887
1869
|
],
|
|
1888
1870
|
"condition": {
|
|
1889
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode
|
|
1871
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
|
|
1890
1872
|
}
|
|
1891
1873
|
},
|
|
1892
1874
|
{
|
|
@@ -1912,7 +1894,7 @@
|
|
|
1912
1894
|
}
|
|
1913
1895
|
],
|
|
1914
1896
|
"condition": {
|
|
1915
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode
|
|
1897
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
|
|
1916
1898
|
}
|
|
1917
1899
|
},
|
|
1918
1900
|
{
|
|
@@ -1935,7 +1917,7 @@
|
|
|
1935
1917
|
}
|
|
1936
1918
|
],
|
|
1937
1919
|
"condition": {
|
|
1938
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode
|
|
1920
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ataDevices[arrayIndices[1]].displayMode > 0;"
|
|
1939
1921
|
}
|
|
1940
1922
|
}
|
|
1941
1923
|
],
|
|
@@ -1984,7 +1966,7 @@
|
|
|
1984
1966
|
"accounts[].atwDevices[].refreshInterval"
|
|
1985
1967
|
],
|
|
1986
1968
|
"condition": {
|
|
1987
|
-
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode
|
|
1969
|
+
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
|
|
1988
1970
|
}
|
|
1989
1971
|
},
|
|
1990
1972
|
{
|
|
@@ -2005,7 +1987,7 @@
|
|
|
2005
1987
|
"accounts[].atwDevices[].temperatureSensorReturnZone2"
|
|
2006
1988
|
],
|
|
2007
1989
|
"condition": {
|
|
2008
|
-
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode
|
|
1990
|
+
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
|
|
2009
1991
|
}
|
|
2010
1992
|
},
|
|
2011
1993
|
{
|
|
@@ -2031,7 +2013,7 @@
|
|
|
2031
2013
|
}
|
|
2032
2014
|
],
|
|
2033
2015
|
"condition": {
|
|
2034
|
-
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode
|
|
2016
|
+
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
|
|
2035
2017
|
}
|
|
2036
2018
|
},
|
|
2037
2019
|
{
|
|
@@ -2054,7 +2036,7 @@
|
|
|
2054
2036
|
}
|
|
2055
2037
|
],
|
|
2056
2038
|
"condition": {
|
|
2057
|
-
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode
|
|
2039
|
+
"functionBody": "return model.accounts[arrayIndices[0]].atwDevices[arrayIndices[1]].displayMode > 0;"
|
|
2058
2040
|
}
|
|
2059
2041
|
}
|
|
2060
2042
|
],
|
|
@@ -2102,7 +2084,7 @@
|
|
|
2102
2084
|
"accounts[].ervDevices[].refreshInterval"
|
|
2103
2085
|
],
|
|
2104
2086
|
"condition": {
|
|
2105
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode
|
|
2087
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
|
|
2106
2088
|
}
|
|
2107
2089
|
},
|
|
2108
2090
|
{
|
|
@@ -2117,7 +2099,7 @@
|
|
|
2117
2099
|
"accounts[].ervDevices[].temperatureSensorSupply"
|
|
2118
2100
|
],
|
|
2119
2101
|
"condition": {
|
|
2120
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode
|
|
2102
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
|
|
2121
2103
|
}
|
|
2122
2104
|
},
|
|
2123
2105
|
{
|
|
@@ -2143,7 +2125,7 @@
|
|
|
2143
2125
|
}
|
|
2144
2126
|
],
|
|
2145
2127
|
"condition": {
|
|
2146
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode
|
|
2128
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
|
|
2147
2129
|
}
|
|
2148
2130
|
},
|
|
2149
2131
|
{
|
|
@@ -2166,7 +2148,7 @@
|
|
|
2166
2148
|
}
|
|
2167
2149
|
],
|
|
2168
2150
|
"condition": {
|
|
2169
|
-
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode
|
|
2151
|
+
"functionBody": "return model.accounts[arrayIndices[0]].ervDevices[arrayIndices[1]].displayMode > 0;"
|
|
2170
2152
|
}
|
|
2171
2153
|
}
|
|
2172
2154
|
],
|
|
@@ -2231,8 +2213,7 @@
|
|
|
2231
2213
|
"key": "accounts[].restFul",
|
|
2232
2214
|
"title": "RESTFul",
|
|
2233
2215
|
"items": [
|
|
2234
|
-
"accounts[].restFul.enable"
|
|
2235
|
-
"accounts[].restFul.debug"
|
|
2216
|
+
"accounts[].restFul.enable"
|
|
2236
2217
|
]
|
|
2237
2218
|
},
|
|
2238
2219
|
{
|
|
@@ -2244,7 +2225,6 @@
|
|
|
2244
2225
|
"accounts[].mqtt.port",
|
|
2245
2226
|
"accounts[].mqtt.clientId",
|
|
2246
2227
|
"accounts[].mqtt.prefix",
|
|
2247
|
-
"accounts[].mqtt.debug",
|
|
2248
2228
|
{
|
|
2249
2229
|
"key": "accounts[].mqtt.auth",
|
|
2250
2230
|
"title": "Authorization",
|
package/index.js
CHANGED
|
@@ -145,15 +145,15 @@ class MelCloudPlatform {
|
|
|
145
145
|
let configuredDevice;
|
|
146
146
|
switch (deviceType) {
|
|
147
147
|
case 0: //ATA
|
|
148
|
-
configuredDevice = new DeviceAta(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile,
|
|
148
|
+
configuredDevice = new DeviceAta(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, useFahrenheit, restFul, mqtt);
|
|
149
149
|
break;
|
|
150
150
|
case 1: //ATW
|
|
151
|
-
configuredDevice = new DeviceAtw(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile,
|
|
151
|
+
configuredDevice = new DeviceAtw(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, useFahrenheit, restFul, mqtt);
|
|
152
152
|
break;
|
|
153
153
|
case 2:
|
|
154
154
|
break;
|
|
155
155
|
case 3: //ERV
|
|
156
|
-
configuredDevice = new DeviceErv(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile,
|
|
156
|
+
configuredDevice = new DeviceErv(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, useFahrenheit, restFul, mqtt);
|
|
157
157
|
break;
|
|
158
158
|
default:
|
|
159
159
|
if (logLevel.warn) log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, unknown device: ${deviceType}.`);
|
|
@@ -181,10 +181,10 @@ class MelCloudPlatform {
|
|
|
181
181
|
if (logLevel.success) log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, Published as external accessory.`);
|
|
182
182
|
|
|
183
183
|
//start account impulse generator
|
|
184
|
-
await melCloud.
|
|
184
|
+
await melCloud.startStopImpulseGenerator(true, [{ name: 'checkDevicesList', sampling: refreshInterval }]);
|
|
185
185
|
|
|
186
|
-
await impulseGenerator.
|
|
187
|
-
await configuredDevice.
|
|
186
|
+
await impulseGenerator.state(false);
|
|
187
|
+
await configuredDevice.startStopImpulseGenerator(true, [{ name: 'checkState', sampling: deviceRefreshInterval }]);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
} catch (error) {
|
|
@@ -195,7 +195,7 @@ class MelCloudPlatform {
|
|
|
195
195
|
});
|
|
196
196
|
|
|
197
197
|
//start impulse generator
|
|
198
|
-
await impulseGenerator.
|
|
198
|
+
await impulseGenerator.state(true, [{ name: 'start', sampling: 60000 }]);
|
|
199
199
|
} catch (error) {
|
|
200
200
|
if (logLevel.error) log.error(`${accountName}, Did finish launching error: ${error.message ?? error}.`);
|
|
201
201
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "3.10.0-beta.
|
|
4
|
+
"version": "3.10.0-beta.28",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"LICENSE"
|
|
32
32
|
],
|
|
33
33
|
"engines": {
|
|
34
|
-
"homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.30 || ^2.0.0-alpha.
|
|
34
|
+
"homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.30 || ^2.0.0-alpha.60",
|
|
35
35
|
"node": "^20 || ^22 || ^24"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
package/src/deviceata.js
CHANGED
|
@@ -6,7 +6,7 @@ import { TemperatureDisplayUnits, AirConditioner } from './constants.js';
|
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
8
|
class DeviceAta extends EventEmitter {
|
|
9
|
-
constructor(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile,
|
|
9
|
+
constructor(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, useFahrenheit, restFul, mqtt) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
12
12
|
Accessory = api.platformAccessory;
|
|
@@ -22,8 +22,8 @@ class DeviceAta extends EventEmitter {
|
|
|
22
22
|
this.heatDryFanMode = device.heatDryFanMode || 1; //NONE, HEAT, DRY, FAN
|
|
23
23
|
this.coolDryFanMode = device.coolDryFanMode || 1; //NONE, COOL, DRY, FAN
|
|
24
24
|
this.autoDryFanMode = device.autoDryFanMode || 1; //NONE, AUTO, DRY, FAN
|
|
25
|
-
this.presets = device.presets || [];
|
|
26
|
-
this.buttons = device.buttonsSensors || [];
|
|
25
|
+
this.presets = (device.presets || []).filter(preset => (preset.displayType ?? 0) > 0);
|
|
26
|
+
this.buttons = (device.buttonsSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0);
|
|
27
27
|
this.logDeviceInfo = account.log?.deviceInfo || false;
|
|
28
28
|
this.logInfo = account.log?.info || false;
|
|
29
29
|
this.logWarn = account.log?.warn || false;
|
|
@@ -34,8 +34,6 @@ class DeviceAta extends EventEmitter {
|
|
|
34
34
|
this.deviceName = deviceName;
|
|
35
35
|
this.deviceTypeText = deviceTypeText;
|
|
36
36
|
this.devicesFile = devicesFile;
|
|
37
|
-
this.refreshInterval = refreshInterval;
|
|
38
|
-
this.startPrepareAccessory = true;
|
|
39
37
|
this.displayDeviceInfo = true;
|
|
40
38
|
|
|
41
39
|
//external integrations
|
|
@@ -45,42 +43,22 @@ class DeviceAta extends EventEmitter {
|
|
|
45
43
|
this.mqttConnected = false;
|
|
46
44
|
|
|
47
45
|
//presets configured
|
|
48
|
-
this.presetsConfigured = [];
|
|
49
46
|
for (const preset of this.presets) {
|
|
50
|
-
const displayType = preset.displayType;
|
|
51
|
-
if (!displayType) {
|
|
52
|
-
continue;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const presetyServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][displayType];
|
|
56
|
-
const presetCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
57
47
|
preset.name = preset.name || 'Preset'
|
|
58
|
-
preset.serviceType =
|
|
59
|
-
preset.characteristicType =
|
|
48
|
+
preset.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][preset.displayType];
|
|
49
|
+
preset.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][preset.displayType];
|
|
60
50
|
preset.state = false;
|
|
61
51
|
preset.previousSettings = {};
|
|
62
|
-
this.presetsConfigured.push(preset);
|
|
63
52
|
}
|
|
64
|
-
this.presetsConfiguredCount = this.presetsConfigured.length || 0;
|
|
65
53
|
|
|
66
54
|
//buttons configured
|
|
67
|
-
this.buttonsConfigured = [];
|
|
68
55
|
for (const button of this.buttons) {
|
|
69
|
-
const displayType = button.displayType;
|
|
70
|
-
if (!displayType) {
|
|
71
|
-
continue;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const buttonServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][displayType];
|
|
75
|
-
const buttonCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
76
56
|
button.name = button.name || 'Button'
|
|
77
|
-
button.serviceType =
|
|
78
|
-
button.characteristicType =
|
|
57
|
+
button.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][button.displayType];
|
|
58
|
+
button.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][button.displayType];
|
|
79
59
|
button.state = false;
|
|
80
60
|
button.previousValue = null;
|
|
81
|
-
this.buttonsConfigured.push(button);;
|
|
82
61
|
}
|
|
83
|
-
this.buttonsConfiguredCount = this.buttonsConfigured.length || 0;
|
|
84
62
|
|
|
85
63
|
//device data
|
|
86
64
|
this.deviceData = {};
|
|
@@ -98,13 +76,13 @@ class DeviceAta extends EventEmitter {
|
|
|
98
76
|
if (!this.restFulConnected) {
|
|
99
77
|
this.restFul1 = new RestFul({
|
|
100
78
|
port: this.deviceId.toString().slice(-4).replace(/^0/, '9'),
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.restFul1.on('connected', (message) => {
|
|
105
|
-
this.restFulConnected = true;
|
|
106
|
-
this.emit('success', message);
|
|
79
|
+
logWarn: this.logWarn,
|
|
80
|
+
logDebug: this.logDebug
|
|
107
81
|
})
|
|
82
|
+
.on('connected', (message) => {
|
|
83
|
+
this.restFulConnected = true;
|
|
84
|
+
this.emit('success', message);
|
|
85
|
+
})
|
|
108
86
|
.on('set', async (key, value) => {
|
|
109
87
|
try {
|
|
110
88
|
await this.setOverExternalIntegration('RESTFul', this.deviceData, key, value);
|
|
@@ -135,13 +113,13 @@ class DeviceAta extends EventEmitter {
|
|
|
135
113
|
prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
|
|
136
114
|
user: this.mqtt.auth?.user,
|
|
137
115
|
passwd: this.mqtt.auth?.passwd,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.mqtt1.on('connected', (message) => {
|
|
142
|
-
this.mqttConnected = true;
|
|
143
|
-
this.emit('success', message);
|
|
116
|
+
logWarn: this.logWarn,
|
|
117
|
+
logDebug: this.logDebug
|
|
144
118
|
})
|
|
119
|
+
.on('connected', (message) => {
|
|
120
|
+
this.mqttConnected = true;
|
|
121
|
+
this.emit('success', message);
|
|
122
|
+
})
|
|
145
123
|
.on('subscribed', (message) => {
|
|
146
124
|
this.emit('success', message);
|
|
147
125
|
})
|
|
@@ -247,15 +225,14 @@ class DeviceAta extends EventEmitter {
|
|
|
247
225
|
};
|
|
248
226
|
}
|
|
249
227
|
|
|
250
|
-
async
|
|
228
|
+
async startStopImpulseGenerator(state, timers = []) {
|
|
251
229
|
try {
|
|
252
|
-
//start
|
|
253
|
-
await
|
|
254
|
-
await this.melCloudAta.impulseGenerator.start([{ name: 'checkState', sampling: this.refreshInterval }]);
|
|
230
|
+
//start impulse generator
|
|
231
|
+
await this.melCloudAta.impulseGenerator.state(state, timers)
|
|
255
232
|
return true;
|
|
256
233
|
} catch (error) {
|
|
257
234
|
throw new Error(`Impulse generator start error: ${error}`);
|
|
258
|
-
}
|
|
235
|
+
}
|
|
259
236
|
}
|
|
260
237
|
|
|
261
238
|
//prepare accessory
|
|
@@ -632,10 +609,10 @@ class DeviceAta extends EventEmitter {
|
|
|
632
609
|
};
|
|
633
610
|
|
|
634
611
|
//presets services
|
|
635
|
-
if (this.
|
|
612
|
+
if (this.presets.length > 0) {
|
|
636
613
|
if (this.logDebug) this.emit('debug', `Prepare presets services`);
|
|
637
614
|
this.presetsServices = [];
|
|
638
|
-
this.
|
|
615
|
+
this.presets.forEach((preset, i) => {
|
|
639
616
|
const presetData = presetsOnServer.find(p => p.ID === preset.Id);
|
|
640
617
|
|
|
641
618
|
//get preset name
|
|
@@ -691,10 +668,10 @@ class DeviceAta extends EventEmitter {
|
|
|
691
668
|
};
|
|
692
669
|
|
|
693
670
|
//buttons services
|
|
694
|
-
if (this.
|
|
671
|
+
if (this.buttons.length > 0) {
|
|
695
672
|
if (this.logDebug) this.emit('debug', `Prepare buttons/sensors services`);
|
|
696
673
|
this.buttonsServices = [];
|
|
697
|
-
this.
|
|
674
|
+
this.buttons.forEach((button, i) => {
|
|
698
675
|
//get button mode
|
|
699
676
|
const mode = button.mode;
|
|
700
677
|
|
|
@@ -1200,8 +1177,8 @@ class DeviceAta extends EventEmitter {
|
|
|
1200
1177
|
this.outdoorTemperatureSensorService?.updateCharacteristic(Characteristic.CurrentTemperature, outdoorTemperature);
|
|
1201
1178
|
|
|
1202
1179
|
//update presets state
|
|
1203
|
-
if (this.
|
|
1204
|
-
this.
|
|
1180
|
+
if (this.presets.length > 0) {
|
|
1181
|
+
this.presets.forEach((preset, i) => {
|
|
1205
1182
|
const presetData = presetsOnServer.find(p => p.ID === preset.Id);
|
|
1206
1183
|
|
|
1207
1184
|
preset.state = presetData ? (presetData.Power === power
|
|
@@ -1217,8 +1194,8 @@ class DeviceAta extends EventEmitter {
|
|
|
1217
1194
|
};
|
|
1218
1195
|
|
|
1219
1196
|
//update buttons state
|
|
1220
|
-
if (this.
|
|
1221
|
-
this.
|
|
1197
|
+
if (this.buttons.length > 0) {
|
|
1198
|
+
this.buttons.forEach((button, i) => {
|
|
1222
1199
|
const mode = button.mode;
|
|
1223
1200
|
switch (mode) {
|
|
1224
1201
|
case 0: //POWER ON,OFF
|
package/src/deviceatw.js
CHANGED
|
@@ -6,7 +6,7 @@ import { TemperatureDisplayUnits, HeatPump } from './constants.js';
|
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
8
|
class DeviceAtw extends EventEmitter {
|
|
9
|
-
constructor(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile,
|
|
9
|
+
constructor(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, useFahrenheit, restFul, mqtt) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
12
12
|
Accessory = api.platformAccessory;
|
|
@@ -27,8 +27,8 @@ class DeviceAtw extends EventEmitter {
|
|
|
27
27
|
this.temperatureSensorReturnWaterTank = device.temperatureSensorReturnWaterTank || false;
|
|
28
28
|
this.temperatureSensorFlowZone2 = device.temperatureSensorFlowZone2 || false;
|
|
29
29
|
this.temperatureSensorReturnZone2 = device.temperatureSensorReturnZone2 || false;
|
|
30
|
-
this.presets = device.presets || [];
|
|
31
|
-
this.buttons = device.buttonsSensors || [];
|
|
30
|
+
this.presets = (device.presets || []).filter(preset => (preset.displayType ?? 0) > 0);
|
|
31
|
+
this.buttons = (device.buttonsSensors || []).filter(button => (button.displayType ?? 0) > 0);
|
|
32
32
|
this.logDeviceInfo = account.log?.deviceInfo || false;
|
|
33
33
|
this.logInfo = account.log?.info || false;
|
|
34
34
|
this.logWarn = account.log?.warn || false;
|
|
@@ -39,8 +39,6 @@ class DeviceAtw extends EventEmitter {
|
|
|
39
39
|
this.deviceName = deviceName;
|
|
40
40
|
this.deviceTypeText = deviceTypeText;
|
|
41
41
|
this.devicesFile = devicesFile;
|
|
42
|
-
this.refreshInterval = refreshInterval;
|
|
43
|
-
this.startPrepareAccessory = true;
|
|
44
42
|
this.displayDeviceInfo = true;
|
|
45
43
|
|
|
46
44
|
//external integrations
|
|
@@ -50,42 +48,22 @@ class DeviceAtw extends EventEmitter {
|
|
|
50
48
|
this.mqttConnected = false;
|
|
51
49
|
|
|
52
50
|
//presets configured
|
|
53
|
-
this.presetsConfigured = [];
|
|
54
51
|
for (const preset of this.presets) {
|
|
55
|
-
const displayType = preset.displayType;
|
|
56
|
-
if (!displayType) {
|
|
57
|
-
continue;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const presetyServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][displayType];
|
|
61
|
-
const presetCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
62
52
|
preset.name = preset.name || 'Preset'
|
|
63
|
-
preset.serviceType =
|
|
64
|
-
preset.characteristicType =
|
|
53
|
+
preset.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][preset.displayType];
|
|
54
|
+
preset.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][preset.displayType];
|
|
65
55
|
preset.state = false;
|
|
66
56
|
preset.previousSettings = {};
|
|
67
|
-
this.presetsConfigured.push(preset);
|
|
68
57
|
}
|
|
69
|
-
this.presetsConfiguredCount = this.presetsConfigured.length || 0;
|
|
70
58
|
|
|
71
59
|
//buttons configured
|
|
72
|
-
this.buttonsConfigured = [];
|
|
73
60
|
for (const button of this.buttons) {
|
|
74
|
-
const displayType = button.displayType;
|
|
75
|
-
if (!displayType) {
|
|
76
|
-
continue;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const buttonServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][displayType];
|
|
80
|
-
const buttonCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
81
61
|
button.name = button.name || 'Button'
|
|
82
|
-
button.serviceType =
|
|
83
|
-
button.characteristicType =
|
|
62
|
+
button.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][button.displayType];
|
|
63
|
+
button.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][button.displayType];
|
|
84
64
|
button.state = false;
|
|
85
65
|
button.previousValue = null;
|
|
86
|
-
this.buttonsConfigured.push(button);;
|
|
87
66
|
}
|
|
88
|
-
this.buttonsConfiguredCount = this.buttonsConfigured.length || 0;
|
|
89
67
|
|
|
90
68
|
//device data
|
|
91
69
|
this.deviceData = {};
|
|
@@ -103,13 +81,13 @@ class DeviceAtw extends EventEmitter {
|
|
|
103
81
|
if (!this.restFulConnected) {
|
|
104
82
|
this.restFul1 = new RestFul({
|
|
105
83
|
port: this.deviceId.toString().slice(-4).replace(/^0/, '9'),
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.restFul1.on('connected', (message) => {
|
|
110
|
-
this.restFulConnected = true;
|
|
111
|
-
this.emit('success', message);
|
|
84
|
+
logWarn: this.logWarn,
|
|
85
|
+
logDebug: this.logDebug
|
|
112
86
|
})
|
|
87
|
+
.on('connected', (message) => {
|
|
88
|
+
this.restFulConnected = true;
|
|
89
|
+
this.emit('success', message);
|
|
90
|
+
})
|
|
113
91
|
.on('set', async (key, value) => {
|
|
114
92
|
try {
|
|
115
93
|
await this.setOverExternalIntegration('RESTFul', this.deviceData, key, value);
|
|
@@ -140,13 +118,13 @@ class DeviceAtw extends EventEmitter {
|
|
|
140
118
|
prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
|
|
141
119
|
user: this.mqtt.auth?.user,
|
|
142
120
|
passwd: this.mqtt.auth?.passwd,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.mqtt1.on('connected', (message) => {
|
|
147
|
-
this.mqttConnected = true;
|
|
148
|
-
this.emit('success', message);
|
|
121
|
+
logWarn: this.logWarn,
|
|
122
|
+
logDebug: this.logDebug
|
|
149
123
|
})
|
|
124
|
+
.on('connected', (message) => {
|
|
125
|
+
this.mqttConnected = true;
|
|
126
|
+
this.emit('success', message);
|
|
127
|
+
})
|
|
150
128
|
.on('subscribed', (message) => {
|
|
151
129
|
this.emit('success', message);
|
|
152
130
|
})
|
|
@@ -272,15 +250,14 @@ class DeviceAtw extends EventEmitter {
|
|
|
272
250
|
};
|
|
273
251
|
}
|
|
274
252
|
|
|
275
|
-
async
|
|
253
|
+
async startStopImpulseGenerator(state, timers = []) {
|
|
276
254
|
try {
|
|
277
|
-
//start
|
|
278
|
-
await
|
|
279
|
-
await this.melCloudAtw.impulseGenerator.start([{ name: 'checkState', sampling: this.refreshInterval }]);
|
|
255
|
+
//start impulse generator
|
|
256
|
+
await this.melCloudAtw.impulseGenerator.state(state, timers)
|
|
280
257
|
return true;
|
|
281
258
|
} catch (error) {
|
|
282
259
|
throw new Error(`Impulse generator start error: ${error}`);
|
|
283
|
-
}
|
|
260
|
+
}
|
|
284
261
|
}
|
|
285
262
|
|
|
286
263
|
//prepare accessory
|
|
@@ -1057,10 +1034,10 @@ class DeviceAtw extends EventEmitter {
|
|
|
1057
1034
|
};
|
|
1058
1035
|
|
|
1059
1036
|
//presets services
|
|
1060
|
-
if (this.
|
|
1037
|
+
if (this.presets.length > 0) {
|
|
1061
1038
|
if (this.logDebug) this.emit('debug', `Prepare presets services`);
|
|
1062
1039
|
this.presetsServices = [];
|
|
1063
|
-
this.
|
|
1040
|
+
this.presets.forEach((preset, i) => {
|
|
1064
1041
|
const presetData = presetsOnServer.find(p => p.ID === preset.Id);
|
|
1065
1042
|
|
|
1066
1043
|
//get preset name
|
|
@@ -1128,10 +1105,10 @@ class DeviceAtw extends EventEmitter {
|
|
|
1128
1105
|
};
|
|
1129
1106
|
|
|
1130
1107
|
//buttons services
|
|
1131
|
-
if (this.
|
|
1108
|
+
if (this.buttons.length > 0) {
|
|
1132
1109
|
if (this.logDebug) this.emit('debug', `Prepare buttons services`);
|
|
1133
1110
|
this.buttonsServices = [];
|
|
1134
|
-
this.
|
|
1111
|
+
this.buttons.lengthforEach((button, i) => {
|
|
1135
1112
|
//get button mode
|
|
1136
1113
|
const mode = button.mode;
|
|
1137
1114
|
|
|
@@ -1819,8 +1796,8 @@ class DeviceAtw extends EventEmitter {
|
|
|
1819
1796
|
this.accessory = obj;
|
|
1820
1797
|
|
|
1821
1798
|
//update presets state
|
|
1822
|
-
if (this.
|
|
1823
|
-
this.
|
|
1799
|
+
if (this.presets.length > 0) {
|
|
1800
|
+
this.presets.forEach((preset, i) => {
|
|
1824
1801
|
const presetData = presetsOnServer.find(p => p.ID === preset.Id);
|
|
1825
1802
|
|
|
1826
1803
|
preset.state = presetData ? (presetData.Power === power
|
|
@@ -1842,8 +1819,8 @@ class DeviceAtw extends EventEmitter {
|
|
|
1842
1819
|
};
|
|
1843
1820
|
|
|
1844
1821
|
//update buttons state
|
|
1845
|
-
if (this.
|
|
1846
|
-
this.
|
|
1822
|
+
if (this.buttons.length > 0) {
|
|
1823
|
+
this.buttons.forEach((button, i) => {
|
|
1847
1824
|
const mode = button.mode;
|
|
1848
1825
|
switch (mode) {
|
|
1849
1826
|
case 0: //POWER ON,OFF
|
package/src/deviceerv.js
CHANGED
|
@@ -6,7 +6,7 @@ import { TemperatureDisplayUnits, Ventilation } from './constants.js';
|
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
8
|
class DeviceErv extends EventEmitter {
|
|
9
|
-
constructor(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile,
|
|
9
|
+
constructor(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, useFahrenheit, restFul, mqtt) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
12
12
|
Accessory = api.platformAccessory;
|
|
@@ -20,8 +20,8 @@ class DeviceErv extends EventEmitter {
|
|
|
20
20
|
this.temperatureSensor = device.temperatureSensor || false;
|
|
21
21
|
this.temperatureSensorOutdoor = device.temperatureSensorOutdoor || false;
|
|
22
22
|
this.temperatureSensorSupply = device.temperatureSensorSupply || false;
|
|
23
|
-
this.presets = device.presets || [];
|
|
24
|
-
this.buttons = device.buttonsSensors || [];
|
|
23
|
+
this.presets = (device.presets || []).filter(preset => (preset.displayType ?? 0) > 0);
|
|
24
|
+
this.buttons = (device.buttonsSensors || []).filter(button => (button.displayType ?? 0) > 0);
|
|
25
25
|
this.logDeviceInfo = account.log?.deviceInfo || false;
|
|
26
26
|
this.logInfo = account.log?.info || false;
|
|
27
27
|
this.logWarn = account.log?.warn || false;
|
|
@@ -32,8 +32,6 @@ class DeviceErv extends EventEmitter {
|
|
|
32
32
|
this.deviceName = deviceName;
|
|
33
33
|
this.deviceTypeText = deviceTypeText;
|
|
34
34
|
this.devicesFile = devicesFile;
|
|
35
|
-
this.refreshInterval = refreshInterval;
|
|
36
|
-
this.startPrepareAccessory = true;
|
|
37
35
|
this.displayDeviceInfo = true;
|
|
38
36
|
|
|
39
37
|
//external integrations
|
|
@@ -43,42 +41,22 @@ class DeviceErv extends EventEmitter {
|
|
|
43
41
|
this.mqttConnected = false;
|
|
44
42
|
|
|
45
43
|
//presets configured
|
|
46
|
-
this.presetsConfigured = [];
|
|
47
44
|
for (const preset of this.presets) {
|
|
48
|
-
const displayType = preset.displayType;
|
|
49
|
-
if (!displayType) {
|
|
50
|
-
continue;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const presetyServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][displayType];
|
|
54
|
-
const presetCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
55
45
|
preset.name = preset.name || 'Preset'
|
|
56
|
-
preset.serviceType =
|
|
57
|
-
preset.characteristicType =
|
|
46
|
+
preset.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][preset.displayType];
|
|
47
|
+
preset.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][preset.displayType];
|
|
58
48
|
preset.state = false;
|
|
59
49
|
preset.previousSettings = {};
|
|
60
|
-
this.presetsConfigured.push(preset);
|
|
61
50
|
}
|
|
62
|
-
this.presetsConfiguredCount = this.presetsConfigured.length || 0;
|
|
63
51
|
|
|
64
52
|
//buttons configured
|
|
65
|
-
this.buttonsConfigured = [];
|
|
66
53
|
for (const button of this.buttons) {
|
|
67
|
-
const displayType = button.displayType;
|
|
68
|
-
if (!displayType) {
|
|
69
|
-
continue;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const buttonServiceType = ['', Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][displayType];
|
|
73
|
-
const buttonCharacteristicType = ['', Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][displayType];
|
|
74
54
|
button.name = button.name || 'Button'
|
|
75
|
-
button.serviceType =
|
|
76
|
-
button.characteristicType =
|
|
55
|
+
button.serviceType = [null, Service.Outlet, Service.Switch, Service.MotionSensor, Service.OccupancySensor, Service.ContactSensor][button.displayType];
|
|
56
|
+
button.characteristicType = [null, Characteristic.On, Characteristic.On, Characteristic.MotionDetected, Characteristic.OccupancyDetected, Characteristic.ContactSensorState][button.displayType];
|
|
77
57
|
button.state = false;
|
|
78
58
|
button.previousValue = null;
|
|
79
|
-
this.buttonsConfigured.push(button);;
|
|
80
59
|
}
|
|
81
|
-
this.buttonsConfiguredCount = this.buttonsConfigured.length || 0;
|
|
82
60
|
|
|
83
61
|
//device data
|
|
84
62
|
this.deviceData = {};
|
|
@@ -96,13 +74,13 @@ class DeviceErv extends EventEmitter {
|
|
|
96
74
|
if (!this.restFulConnected) {
|
|
97
75
|
this.restFul1 = new RestFul({
|
|
98
76
|
port: this.deviceId.toString().slice(-4).replace(/^0/, '9'),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.restFul1.on('connected', (message) => {
|
|
103
|
-
this.restFulConnected = true;
|
|
104
|
-
this.emit('success', message);
|
|
77
|
+
logWarn: this.logWarn,
|
|
78
|
+
logDebug: this.logDebug
|
|
105
79
|
})
|
|
80
|
+
.on('connected', (message) => {
|
|
81
|
+
this.restFulConnected = true;
|
|
82
|
+
this.emit('success', message);
|
|
83
|
+
})
|
|
106
84
|
.on('set', async (key, value) => {
|
|
107
85
|
try {
|
|
108
86
|
await this.setOverExternalIntegration('RESTFul', this.deviceData, key, value);
|
|
@@ -133,13 +111,13 @@ class DeviceErv extends EventEmitter {
|
|
|
133
111
|
prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeText}/${this.deviceName}` : `melcloud/${this.deviceTypeText}/${this.deviceName}`,
|
|
134
112
|
user: this.mqtt.auth?.user,
|
|
135
113
|
passwd: this.mqtt.auth?.passwd,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.mqtt1.on('connected', (message) => {
|
|
140
|
-
this.mqttConnected = true;
|
|
141
|
-
this.emit('success', message);
|
|
114
|
+
logWarn: this.logWarn,
|
|
115
|
+
logDebug: this.logDebug
|
|
142
116
|
})
|
|
117
|
+
.on('connected', (message) => {
|
|
118
|
+
this.mqttConnected = true;
|
|
119
|
+
this.emit('success', message);
|
|
120
|
+
})
|
|
143
121
|
.on('subscribed', (message) => {
|
|
144
122
|
this.emit('success', message);
|
|
145
123
|
})
|
|
@@ -235,15 +213,14 @@ class DeviceErv extends EventEmitter {
|
|
|
235
213
|
};
|
|
236
214
|
}
|
|
237
215
|
|
|
238
|
-
async
|
|
216
|
+
async startStopImpulseGenerator(state, timers = []) {
|
|
239
217
|
try {
|
|
240
|
-
//start
|
|
241
|
-
await
|
|
242
|
-
await this.melCloudErv.impulseGenerator.start([{ name: 'checkState', sampling: this.refreshInterval }]);
|
|
218
|
+
//start impulse generator
|
|
219
|
+
await this.melCloudErv.impulseGenerator.state(state, timers)
|
|
243
220
|
return true;
|
|
244
221
|
} catch (error) {
|
|
245
222
|
throw new Error(`Impulse generator start error: ${error}`);
|
|
246
|
-
}
|
|
223
|
+
}
|
|
247
224
|
}
|
|
248
225
|
|
|
249
226
|
//prepare accessory
|
|
@@ -681,10 +658,10 @@ class DeviceErv extends EventEmitter {
|
|
|
681
658
|
}
|
|
682
659
|
|
|
683
660
|
//presets services
|
|
684
|
-
if (this.
|
|
661
|
+
if (this.presets.length > 0) {
|
|
685
662
|
if (this.logDebug) this.emit('debug', `Prepare presets services`);
|
|
686
663
|
this.presetsServices = [];
|
|
687
|
-
this.
|
|
664
|
+
this.presets.forEach((preset, i) => {
|
|
688
665
|
const presetData = presetsOnServer.find(p => p.ID === preset.Id);
|
|
689
666
|
|
|
690
667
|
//get preset name
|
|
@@ -738,10 +715,10 @@ class DeviceErv extends EventEmitter {
|
|
|
738
715
|
};
|
|
739
716
|
|
|
740
717
|
//buttons services
|
|
741
|
-
if (this.
|
|
718
|
+
if (this.buttons.length > 0) {
|
|
742
719
|
if (this.logDebug) this.emit('debug', `Prepare buttons services`);
|
|
743
720
|
this.buttonsServices = [];
|
|
744
|
-
this.
|
|
721
|
+
this.buttons.forEach((button, i) => {
|
|
745
722
|
//get button mode
|
|
746
723
|
const mode = button.mode;
|
|
747
724
|
|
|
@@ -1118,8 +1095,8 @@ class DeviceErv extends EventEmitter {
|
|
|
1118
1095
|
.updateCharacteristic(Characteristic.PM2_5Density, pM25Level);
|
|
1119
1096
|
|
|
1120
1097
|
//update presets state
|
|
1121
|
-
if (this.
|
|
1122
|
-
this.
|
|
1098
|
+
if (this.presets.length > 0) {
|
|
1099
|
+
this.presets.forEach((preset, i) => {
|
|
1123
1100
|
const presetData = presetsOnServer.find(p => p.ID === preset.Id);
|
|
1124
1101
|
|
|
1125
1102
|
preset.state = presetData ? (presetData.Power === power
|
|
@@ -1134,8 +1111,8 @@ class DeviceErv extends EventEmitter {
|
|
|
1134
1111
|
};
|
|
1135
1112
|
|
|
1136
1113
|
//update buttons state
|
|
1137
|
-
if (this.
|
|
1138
|
-
this.
|
|
1114
|
+
if (this.buttons.length > 0) {
|
|
1115
|
+
this.buttons.forEach((button, i) => {
|
|
1139
1116
|
const mode = button.mode;;
|
|
1140
1117
|
switch (mode) {
|
|
1141
1118
|
case 0: //POWER ON,OFF
|
package/src/impulsegenerator.js
CHANGED
|
@@ -7,46 +7,34 @@ class ImpulseGenerator extends EventEmitter {
|
|
|
7
7
|
this.timers = [];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
async
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
async state(state, timers = []) {
|
|
11
|
+
// Stop current timers before new start
|
|
12
|
+
if (this.timersState && state) {
|
|
13
|
+
await this.state(false);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (const timer of timers) {
|
|
19
|
-
this.emit(timer.name);
|
|
20
|
-
|
|
21
|
-
const interval = setInterval(() => {
|
|
22
|
-
this.emit(timer.name);
|
|
23
|
-
}, timer.sampling);
|
|
16
|
+
if (state) {
|
|
17
|
+
if (!Array.isArray(timers)) throw new Error('Timers must be an array');
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
for (const { name, sampling } of timers) {
|
|
20
|
+
if (!name || !sampling) continue;
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
22
|
+
this.emit(name);
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
24
|
+
const interval = setInterval(() => {
|
|
25
|
+
this.emit(name);
|
|
26
|
+
}, sampling);
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
this.timers.push(interval);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
this.timers.forEach(clearInterval);
|
|
32
|
+
this.timers = [];
|
|
40
33
|
}
|
|
41
34
|
|
|
42
|
-
this.timers = [];
|
|
43
|
-
this.state(false);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
state(state) {
|
|
48
35
|
this.timersState = state;
|
|
49
36
|
this.emit('state', state);
|
|
37
|
+
return true;
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
|
package/src/mqtt.js
CHANGED
|
@@ -27,25 +27,25 @@ class Mqtt extends EventEmitter {
|
|
|
27
27
|
this.mqttClient.on('message', (topic, message) => {
|
|
28
28
|
try {
|
|
29
29
|
const obj = JSON.parse(message.toString());
|
|
30
|
-
if (config.
|
|
30
|
+
if (config.logDebug) this.emit('debug', `MQTT Received topic: ${topic}, message: ${JSON.stringify(obj, null, 2)}`);
|
|
31
31
|
const key = Object.keys(obj)[0];
|
|
32
32
|
const value = Object.values(obj)[0];
|
|
33
33
|
this.emit('set', key, value);
|
|
34
34
|
} catch (error) {
|
|
35
|
-
this.emit('warn', `MQTT Parse object error: ${error}`);
|
|
35
|
+
if (config.logWarn) this.emit('warn', `MQTT Parse object error: ${error}`);
|
|
36
36
|
};
|
|
37
37
|
});
|
|
38
38
|
} catch (error) {
|
|
39
|
-
this.emit('warn', `MQTT Connect error: ${error}`);
|
|
39
|
+
if (config.logWarn) this.emit('warn', `MQTT Connect error: ${error}`);
|
|
40
40
|
};
|
|
41
41
|
}).on('publish', async (topic, message) => {
|
|
42
42
|
try {
|
|
43
43
|
const fullTopic = `${config.prefix}/${topic}`;
|
|
44
44
|
const publishMessage = JSON.stringify(message, null, 2);
|
|
45
45
|
await this.mqttClient.publish(fullTopic, publishMessage);
|
|
46
|
-
if (config.
|
|
46
|
+
if (config.logDebug) this.emit('debug', `MQTT Publish topic: ${fullTopic}, message: ${publishMessage}`);
|
|
47
47
|
} catch (error) {
|
|
48
|
-
this.emit('warn', `MQTT Publish error: ${error}`);
|
|
48
|
+
if (config.logWarn) this.emit('warn', `MQTT Publish error: ${error}`);
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
51
|
|
package/src/restful.js
CHANGED
|
@@ -6,8 +6,9 @@ const DEFAULT_MESSAGE = 'This data is not available at this time.';
|
|
|
6
6
|
class RestFul extends EventEmitter {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
super();
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
9
|
+
this.port = config.port;
|
|
10
|
+
this.logWarn = config.logWarn;
|
|
11
|
+
this.logDebug = config.logDebug;
|
|
11
12
|
|
|
12
13
|
this.restFulData = {
|
|
13
14
|
info: DEFAULT_MESSAGE,
|
|
@@ -44,7 +45,7 @@ class RestFul extends EventEmitter {
|
|
|
44
45
|
try {
|
|
45
46
|
const obj = req.body;
|
|
46
47
|
if (!obj || typeof obj !== 'object' || Object.keys(obj).length === 0) {
|
|
47
|
-
this.emit('warn', 'RESTFul Invalid JSON payload');
|
|
48
|
+
if (this.logWarn) this.emit('warn', 'RESTFul Invalid JSON payload');
|
|
48
49
|
return res.status(400).json({ error: 'RESTFul Invalid JSON payload' });
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -53,21 +54,21 @@ class RestFul extends EventEmitter {
|
|
|
53
54
|
this.emit('set', key, value);
|
|
54
55
|
this.update(key, value);
|
|
55
56
|
|
|
56
|
-
if (this.
|
|
57
|
+
if (this.logDebug) this.emit('debug', `RESTFul post data: ${JSON.stringify(obj, null, 2)}`);
|
|
57
58
|
|
|
58
59
|
res.json({ success: true, received: obj });
|
|
59
60
|
} catch (error) {
|
|
60
|
-
this.emit('warn', `RESTFul Parse error: ${error}`);
|
|
61
|
+
if (this.logWarn) this.emit('warn', `RESTFul Parse error: ${error}`);
|
|
61
62
|
res.status(500).json({ error: 'RESTFul Internal Server Error' });
|
|
62
63
|
}
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
// Start the server
|
|
66
|
-
app.listen(this.
|
|
67
|
+
app.listen(this.port, () => {
|
|
67
68
|
this.emit('connected', `RESTful started on port: ${this.restFulPort}`);
|
|
68
69
|
});
|
|
69
70
|
} catch (error) {
|
|
70
|
-
this.emit('warn', `RESTful Connect error: ${error}`);
|
|
71
|
+
if (this.logWarn) this.emit('warn', `RESTful Connect error: ${error}`);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -75,11 +76,11 @@ class RestFul extends EventEmitter {
|
|
|
75
76
|
if (this.restFulData.hasOwnProperty(path)) {
|
|
76
77
|
this.restFulData[path] = data;
|
|
77
78
|
} else {
|
|
78
|
-
this.emit('warn', `Unknown RESTFul update path: ${path}, data: ${JSON.stringify(data)}`);
|
|
79
|
+
if (this.logWarn) this.emit('warn', `Unknown RESTFul update path: ${path}, data: ${JSON.stringify(data)}`);
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
if (this.
|
|
83
|
+
if (this.logDebug) this.emit('debug', `RESTFul update path: ${path}, data: ${JSON.stringify(data)}`);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|