homebridge-melcloud-control 3.1.4-beta.0 → 3.1.4-beta.10
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/homebridge-ui/public/index.html +45 -60
- package/index.js +16 -21
- package/package.json +2 -2
- package/src/deviceata.js +7 -6
- package/src/deviceatw.js +4 -3
- package/src/deviceerv.js +4 -3
- package/src/melcloud.js +10 -15
- package/src/melcloudata.js +8 -7
- package/src/melcloudatw.js +7 -6
- package/src/melclouderv.js +7 -6
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
const response = await homebridge.request('/connect', payload);
|
|
151
151
|
const info = response.info ?? '';
|
|
152
152
|
const status = response.status;
|
|
153
|
-
const
|
|
153
|
+
const devicesInMelCloud = response.data ?? [];
|
|
154
154
|
|
|
155
155
|
//response status
|
|
156
156
|
switch (status) {
|
|
@@ -165,24 +165,24 @@
|
|
|
165
165
|
ervPresets: [],
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
-
const
|
|
168
|
+
const devicesByTypeInMelCloud = {
|
|
169
169
|
ata: [],
|
|
170
170
|
atw: [],
|
|
171
171
|
erv: []
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
//get devices by type
|
|
175
|
-
for (const
|
|
176
|
-
const deviceType =
|
|
177
|
-
const pusDeviceTypeAta = deviceType === 0 ?
|
|
178
|
-
const pusDeviceTypeAtw = deviceType === 1 ?
|
|
179
|
-
const pusDeviceTypeErv = deviceType === 3 ?
|
|
174
|
+
//get devices from melcloud by type
|
|
175
|
+
for (const deviceInMelcloud of devicesInMelCloud) {
|
|
176
|
+
const deviceType = devicesInMelCloud.Type;
|
|
177
|
+
const pusDeviceTypeAta = deviceType === 0 ? devicesByTypeInMelCloud.ata.push(deviceInMelcloud) : false;
|
|
178
|
+
const pusDeviceTypeAtw = deviceType === 1 ? devicesByTypeInMelCloud.atw.push(deviceInMelcloud) : false;
|
|
179
|
+
const pusDeviceTypeErv = deviceType === 3 ? devicesByTypeInMelCloud.erv.push(deviceInMelcloud) : false;
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
//devices
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
182
|
+
//devices in config
|
|
183
|
+
const ataDevicesInConfig = pluginConfig[0].accounts[this.deviceIndex].ataDevices ?? [];
|
|
184
|
+
const atwDevicesInConfig = pluginConfig[0].accounts[this.deviceIndex].atwDevices ?? [];
|
|
185
|
+
const ervDevicesInConfig = pluginConfig[0].accounts[this.deviceIndex].ervDevices ?? [];
|
|
186
186
|
|
|
187
187
|
//info text
|
|
188
188
|
let textAta = 'ATA: 0';
|
|
@@ -196,7 +196,7 @@
|
|
|
196
196
|
let ervPresetsCount = 0;
|
|
197
197
|
|
|
198
198
|
//device ata
|
|
199
|
-
|
|
199
|
+
devicesByTypeInMelCloud.ata.forEach((device, index) => {
|
|
200
200
|
const deviceId = device.DeviceID;
|
|
201
201
|
const deviceType = device.Type;
|
|
202
202
|
const deviceName = device.DeviceName;
|
|
@@ -217,14 +217,14 @@
|
|
|
217
217
|
buttonsSensors: []
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
-
const deviceExistsInConfig =
|
|
220
|
+
const deviceExistsInConfig = ataDevicesInConfig.some(device => device.id === deviceId);
|
|
221
221
|
if (!deviceExistsInConfig) {
|
|
222
|
-
|
|
222
|
+
ataDevicesInConfig.push(deviceAta);
|
|
223
223
|
newDevices.ata.push(deviceAta);
|
|
224
224
|
};
|
|
225
225
|
|
|
226
|
-
//presets
|
|
227
|
-
|
|
226
|
+
//presets of device in melcloud
|
|
227
|
+
devicePresets.forEach((preset) => {
|
|
228
228
|
const presetId = preset.ID;
|
|
229
229
|
const presetName = preset.NumberDescription;
|
|
230
230
|
|
|
@@ -233,26 +233,21 @@
|
|
|
233
233
|
preset.displayType == 0;
|
|
234
234
|
preset.namePrefix = false;
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
236
|
+
//find the specific ataDevice to which the preset belongs
|
|
237
|
+
const ataDevice = ataDevicesInConfig.find((configDevice) => configDevice.id === deviceId);
|
|
238
|
+
if (ataDevice && !ataDevice.presets.some((p) => p.id === presetId)) {
|
|
239
|
+
ataDevice.presets.push(preset);
|
|
240
|
+
newDevices.ataPresets.push(preset);
|
|
242
241
|
}
|
|
243
242
|
|
|
244
|
-
|
|
245
|
-
ataDevices[index].presets.push(preset);
|
|
246
|
-
newDevices.ataPresets.push(preset);
|
|
247
|
-
};
|
|
248
|
-
};
|
|
243
|
+
});
|
|
249
244
|
ataPresetsCount = newDevices.ataPresets.length;
|
|
250
245
|
textAtaPresets = `ATA Presets: ${ataPresetsCount}`
|
|
251
246
|
});
|
|
252
247
|
textAta = `ATA: ${newDevices.ata.length}`
|
|
253
248
|
|
|
254
249
|
//device atw
|
|
255
|
-
|
|
250
|
+
devicesByTypeInMelCloud.atw.forEach((device, index) => {
|
|
256
251
|
const deviceId = device.DeviceID;
|
|
257
252
|
const deviceType = device.Type;
|
|
258
253
|
const deviceName = device.DeviceName;
|
|
@@ -279,14 +274,14 @@
|
|
|
279
274
|
buttonsSensors: []
|
|
280
275
|
};
|
|
281
276
|
|
|
282
|
-
const deviceExistsInConfig =
|
|
277
|
+
const deviceExistsInConfig = atwDevicesInConfig.some(device => device.id === deviceId);
|
|
283
278
|
if (!deviceExistsInConfig) {
|
|
284
|
-
|
|
279
|
+
atwDevicesInConfig.push(deviceAtw);
|
|
285
280
|
newDevices.atw.push(deviceAtw);
|
|
286
281
|
};
|
|
287
282
|
|
|
288
|
-
//presets
|
|
289
|
-
|
|
283
|
+
//presets of device in melcloud
|
|
284
|
+
devicePresets.forEach((preset) => {
|
|
290
285
|
const presetId = preset.ID;
|
|
291
286
|
const presetName = preset.NumberDescription;
|
|
292
287
|
|
|
@@ -295,26 +290,21 @@
|
|
|
295
290
|
preset.displayType == 0;
|
|
296
291
|
preset.namePrefix = false;
|
|
297
292
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
293
|
+
//find the specific ataDevice to which the preset belongs
|
|
294
|
+
const atwDevice = atwDevicesInConfig.find((configDevice) => configDevice.id === deviceId);
|
|
295
|
+
if (atwDevice && !atwDevice.presets.some((p) => p.id === presetId)) {
|
|
296
|
+
atwDevice.presets.push(preset);
|
|
297
|
+
newDevices.atwPresets.push(preset);
|
|
304
298
|
}
|
|
305
299
|
|
|
306
|
-
|
|
307
|
-
atwDevices[index].presets.push(preset);
|
|
308
|
-
newDevices.atwPresets.push(preset);
|
|
309
|
-
};
|
|
310
|
-
};
|
|
300
|
+
});
|
|
311
301
|
atwPresetsCount = newDevices.atwPresets.length;
|
|
312
302
|
textAtwPresets = `ATW Presets: ${atwPresetsCount}`
|
|
313
303
|
});
|
|
314
304
|
textAtw = `ATW: ${newDevices.atw.length}`
|
|
315
305
|
|
|
316
306
|
//device erv
|
|
317
|
-
|
|
307
|
+
devicesByTypeInMelCloud.erv.forEach((device, index) => {
|
|
318
308
|
const deviceId = device.DeviceID;
|
|
319
309
|
const deviceType = device.Type;
|
|
320
310
|
const deviceName = device.DeviceName;
|
|
@@ -335,14 +325,14 @@
|
|
|
335
325
|
buttonsSensors: []
|
|
336
326
|
};
|
|
337
327
|
|
|
338
|
-
const deviceExistsInConfig =
|
|
328
|
+
const deviceExistsInConfig = ervDevicesInConfig.some(device => device.id === deviceId);
|
|
339
329
|
if (!deviceExistsInConfig) {
|
|
340
|
-
|
|
330
|
+
ervDevicesInConfig.push(deviceErv);
|
|
341
331
|
newDevices.erv.push(deviceErv);
|
|
342
332
|
};
|
|
343
333
|
|
|
344
|
-
//presets
|
|
345
|
-
|
|
334
|
+
//presets of device in melcloud
|
|
335
|
+
devicePresets.forEach((preset) => {
|
|
346
336
|
const presetId = preset.ID;
|
|
347
337
|
const presetName = preset.NumberDescription;
|
|
348
338
|
|
|
@@ -351,19 +341,14 @@
|
|
|
351
341
|
preset.displayType == 0;
|
|
352
342
|
preset.namePrefix = false;
|
|
353
343
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
344
|
+
//find the specific ataDevice to which the preset belongs
|
|
345
|
+
const ervDevice = ervDevicesInConfig.find((configDevice) => configDevice.id === deviceId);
|
|
346
|
+
if (ervDevice && !ervDevice.presets.some((p) => p.id === presetId)) {
|
|
347
|
+
ervDevice.presets.push(preset);
|
|
348
|
+
newDevices.ervPresets.push(preset);
|
|
360
349
|
}
|
|
361
350
|
|
|
362
|
-
|
|
363
|
-
ervDevices[index].presets.push(preset);
|
|
364
|
-
newDevices.ervPresets.push(preset);
|
|
365
|
-
};
|
|
366
|
-
};
|
|
351
|
+
});
|
|
367
352
|
ervPresetsCount = newDevices.ervPresets.length;
|
|
368
353
|
textErvPresets = `ERV Presets: ${ervPresetsCount}`
|
|
369
354
|
});
|
package/index.js
CHANGED
|
@@ -55,9 +55,9 @@ class MelCloudPlatform {
|
|
|
55
55
|
|
|
56
56
|
//define directory and file paths
|
|
57
57
|
const prefDir = path.join(api.user.storagePath(), 'melcloud');
|
|
58
|
-
const
|
|
58
|
+
const accountFile = `${prefDir}/${accountName}_Account`;
|
|
59
59
|
const buildingsFile = `${prefDir}/${accountName}_Buildings`;
|
|
60
|
-
const
|
|
60
|
+
const devicesFile = `${prefDir}/${accountName}_Devices`;
|
|
61
61
|
|
|
62
62
|
//create directory if it doesn't exist
|
|
63
63
|
try {
|
|
@@ -74,7 +74,7 @@ class MelCloudPlatform {
|
|
|
74
74
|
|
|
75
75
|
try {
|
|
76
76
|
//melcloud account
|
|
77
|
-
const melCloud = new MelCloud(user, passwd, language,
|
|
77
|
+
const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, false);
|
|
78
78
|
melCloud.on('success', (message) => {
|
|
79
79
|
log.success(`Account ${accountName}, ${message}`);
|
|
80
80
|
})
|
|
@@ -103,19 +103,18 @@ class MelCloudPlatform {
|
|
|
103
103
|
const timers = [{ name: 'checkDevicesList', sampling: refreshInterval }];
|
|
104
104
|
melCloud.impulseGenerator.start(timers);
|
|
105
105
|
|
|
106
|
-
//Air Conditioner
|
|
106
|
+
//Air Conditioner 0
|
|
107
107
|
for (const device of account.ataDevices) {
|
|
108
108
|
//chack device from config exist on melcloud
|
|
109
|
-
const
|
|
109
|
+
const deviceId = device.id;
|
|
110
|
+
const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === deviceId);
|
|
110
111
|
if (!deviceExistInMelCloud || device.displayMode === 0) {
|
|
111
112
|
continue;
|
|
112
113
|
};
|
|
113
114
|
|
|
114
|
-
const deviceId = device.id.toString();
|
|
115
115
|
const deviceName = device.name;
|
|
116
116
|
const deviceTypeText = device.typeString;
|
|
117
|
-
const
|
|
118
|
-
const airConditioner = new DeviceAta(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
|
|
117
|
+
const airConditioner = new DeviceAta(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, deviceRefreshInterval)
|
|
119
118
|
airConditioner.on('publishAccessory', (accessory) => {
|
|
120
119
|
|
|
121
120
|
//publish device
|
|
@@ -142,20 +141,18 @@ class MelCloudPlatform {
|
|
|
142
141
|
});
|
|
143
142
|
};
|
|
144
143
|
|
|
145
|
-
//Heat Pump
|
|
144
|
+
//Heat Pump 1
|
|
146
145
|
for (const device of account.atwDevices) {
|
|
147
146
|
//chack device from config exist on melcloud
|
|
147
|
+
const deviceId = device.id;
|
|
148
148
|
const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
|
|
149
149
|
if (!deviceExistInMelCloud || device.displayMode === 0) {
|
|
150
150
|
continue;
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
const deviceId = device.id.toString();
|
|
154
|
-
const deviceType = device.type ?? 1;
|
|
155
153
|
const deviceName = device.name;
|
|
156
|
-
const deviceTypeText =
|
|
157
|
-
const
|
|
158
|
-
const heatPump = new DeviceAtw(api, account, melCloud, device, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
|
|
154
|
+
const deviceTypeText = device.typeString;
|
|
155
|
+
const heatPump = new DeviceAtw(api, account, melCloud, device, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, deviceRefreshInterval)
|
|
159
156
|
heatPump.on('publishAccessory', (accessory) => {
|
|
160
157
|
|
|
161
158
|
//publish device
|
|
@@ -182,20 +179,18 @@ class MelCloudPlatform {
|
|
|
182
179
|
});
|
|
183
180
|
};
|
|
184
181
|
|
|
185
|
-
//Energy Recovery Ventilation
|
|
182
|
+
//Energy Recovery Ventilation 3
|
|
186
183
|
for (const device of account.ervDevices) {
|
|
187
184
|
//chack device from config exist on melcloud
|
|
185
|
+
const deviceId = device.id;
|
|
188
186
|
const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
|
|
189
187
|
if (!deviceExistInMelCloud || device.displayMode === 0) {
|
|
190
188
|
continue;
|
|
191
189
|
};
|
|
192
190
|
|
|
193
|
-
const deviceId = device.id.toString();
|
|
194
|
-
const deviceType = device.type ?? 3;
|
|
195
191
|
const deviceName = device.name;
|
|
196
|
-
const deviceTypeText =
|
|
197
|
-
const
|
|
198
|
-
const energyRecoveryVentilation = new DeviceErv(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
|
|
192
|
+
const deviceTypeText = device.typeString;
|
|
193
|
+
const energyRecoveryVentilation = new DeviceErv(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, deviceRefreshInterval)
|
|
199
194
|
energyRecoveryVentilation.on('publishAccessory', (accessory) => {
|
|
200
195
|
|
|
201
196
|
//publish device
|
|
@@ -222,7 +217,7 @@ class MelCloudPlatform {
|
|
|
222
217
|
});
|
|
223
218
|
};
|
|
224
219
|
} catch (error) {
|
|
225
|
-
log.error(`Account: ${accountName},
|
|
220
|
+
log.error(`Account: ${accountName}, Did finish launching error: ${error.message ?? error}`);
|
|
226
221
|
}
|
|
227
222
|
};
|
|
228
223
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "3.1.4-beta.
|
|
4
|
+
"version": "3.1.4-beta.10",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"engines": {
|
|
31
31
|
"homebridge": "^1.6.0 || ^2.0.0-beta.0",
|
|
32
|
-
"node": "^18.20.4 || ^20.15.1"
|
|
32
|
+
"node": "^18.20.4 || ^20.15.1 || ^22.7.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@homebridge/plugin-ui-utils": "^1.0.3",
|
package/src/deviceata.js
CHANGED
|
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
|
|
|
7
7
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
8
8
|
|
|
9
9
|
class DeviceAta extends EventEmitter {
|
|
10
|
-
constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText,
|
|
10
|
+
constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, refreshInterval) {
|
|
11
11
|
super();
|
|
12
12
|
|
|
13
13
|
Accessory = api.platformAccessory;
|
|
@@ -94,8 +94,9 @@ class DeviceAta extends EventEmitter {
|
|
|
94
94
|
//melcloud device
|
|
95
95
|
this.melCloudAta = new MelCloudAta({
|
|
96
96
|
contextKey: contextKey,
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
accountFile: accountFile,
|
|
98
|
+
devicesFile: devicesFile,
|
|
99
|
+
deviceId: deviceId,
|
|
99
100
|
debugLog: account.enableDebugMode,
|
|
100
101
|
refreshInterval: refreshInterval
|
|
101
102
|
});
|
|
@@ -192,7 +193,6 @@ class DeviceAta extends EventEmitter {
|
|
|
192
193
|
.on('deviceState', async (deviceData, deviceState, useFahrenheit) => {
|
|
193
194
|
//device info
|
|
194
195
|
const displayMode = this.displayMode;
|
|
195
|
-
const inStandbyMode = deviceData.Device.InStandbyMode;
|
|
196
196
|
const hasAutomaticFanSpeed = deviceData.Device.HasAutomaticFanSpeed ?? false;
|
|
197
197
|
const airDirectionFunction = deviceData.Device.AirDirectionFunction ?? false;
|
|
198
198
|
const hasOutdoorTemperature = deviceData.Device.HasOutdoorTemperature ?? false;
|
|
@@ -213,6 +213,9 @@ class DeviceAta extends EventEmitter {
|
|
|
213
213
|
const presetsOnServer = deviceData.Presets ?? [];
|
|
214
214
|
|
|
215
215
|
//device state
|
|
216
|
+
const power = deviceState.Power;
|
|
217
|
+
const offline = deviceState.Offline;
|
|
218
|
+
const inStandbyMode = deviceState.InStandbyMode;
|
|
216
219
|
const roomTemperature = deviceState.RoomTemperature;
|
|
217
220
|
const setTemperature = deviceState.SetTemperature;
|
|
218
221
|
const setFanSpeed = deviceState.SetFanSpeed;
|
|
@@ -224,8 +227,6 @@ class DeviceAta extends EventEmitter {
|
|
|
224
227
|
const prohibitSetTemperature = deviceState.ProhibitSetTemperature;
|
|
225
228
|
const prohibitOperationMode = deviceState.ProhibitOperationMode;
|
|
226
229
|
const prohibitPower = deviceState.ProhibitPower;
|
|
227
|
-
const power = deviceState.Power;
|
|
228
|
-
const offline = deviceState.Offline;
|
|
229
230
|
|
|
230
231
|
//accessory
|
|
231
232
|
this.accessory.presetsOnServer = presetsOnServer;
|
package/src/deviceatw.js
CHANGED
|
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
|
|
|
7
7
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
8
8
|
|
|
9
9
|
class DeviceAtw extends EventEmitter {
|
|
10
|
-
constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText,
|
|
10
|
+
constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, refreshInterval) {
|
|
11
11
|
super();
|
|
12
12
|
|
|
13
13
|
Accessory = api.platformAccessory;
|
|
@@ -90,8 +90,9 @@ class DeviceAtw extends EventEmitter {
|
|
|
90
90
|
//melcloud device
|
|
91
91
|
this.melCloudAtw = new MelCloudAtw({
|
|
92
92
|
contextKey: contextKey,
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
accountFile: accountFile,
|
|
94
|
+
devicesFile: devicesFile,
|
|
95
|
+
deviceId: deviceId,
|
|
95
96
|
debugLog: account.enableDebugMode,
|
|
96
97
|
refreshInterval: refreshInterval
|
|
97
98
|
});
|
package/src/deviceerv.js
CHANGED
|
@@ -7,7 +7,7 @@ const CONSTANTS = require('./constants.json');
|
|
|
7
7
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
8
8
|
|
|
9
9
|
class DeviceErv extends EventEmitter {
|
|
10
|
-
constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText,
|
|
10
|
+
constructor(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountFile, devicesFile, refreshInterval) {
|
|
11
11
|
super();
|
|
12
12
|
|
|
13
13
|
Accessory = api.platformAccessory;
|
|
@@ -93,8 +93,9 @@ class DeviceErv extends EventEmitter {
|
|
|
93
93
|
//melcloud device
|
|
94
94
|
this.melCloudErv = new MelCloudErv({
|
|
95
95
|
contextKey: contextKey,
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
accountFile: accountFile,
|
|
97
|
+
devicesFile: devicesFile,
|
|
98
|
+
deviceId: deviceId,
|
|
98
99
|
debugLog: account.enableDebugMode,
|
|
99
100
|
refreshInterval: refreshInterval
|
|
100
101
|
});
|
package/src/melcloud.js
CHANGED
|
@@ -8,14 +8,15 @@ const ImpulseGenerator = require('./impulsegenerator.js');
|
|
|
8
8
|
const CONSTANTS = require('./constants.json');
|
|
9
9
|
|
|
10
10
|
class MelCloud extends EventEmitter {
|
|
11
|
-
constructor(user, passwd, language,
|
|
11
|
+
constructor(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, requestConfig) {
|
|
12
12
|
super();
|
|
13
|
-
this.
|
|
13
|
+
this.accountFile = accountFile;
|
|
14
14
|
this.buildingsFile = buildingsFile;
|
|
15
|
-
this.
|
|
15
|
+
this.devicesFile = devicesFile;
|
|
16
16
|
this.enableDebugMode = enableDebugMode;
|
|
17
17
|
this.requestConfig = requestConfig;
|
|
18
18
|
this.contextKey = '';
|
|
19
|
+
this.useFahrenheit = 0;
|
|
19
20
|
this.devicesId = [];
|
|
20
21
|
|
|
21
22
|
this.options = {
|
|
@@ -62,6 +63,7 @@ class MelCloud extends EventEmitter {
|
|
|
62
63
|
const account = accountData.data;
|
|
63
64
|
const accountInfo = account.LoginData;
|
|
64
65
|
const contextKey = accountInfo.ContextKey;
|
|
66
|
+
this.useFahrenheit = accountInfo.UseFahrenheit
|
|
65
67
|
this.contextKey = contextKey;
|
|
66
68
|
|
|
67
69
|
//remove sensitive data
|
|
@@ -82,7 +84,7 @@ class MelCloud extends EventEmitter {
|
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
//save melcloud info to the file
|
|
85
|
-
await this.saveData(this.
|
|
87
|
+
await this.saveData(this.accountFile, accountInfo);
|
|
86
88
|
|
|
87
89
|
//emit connect success
|
|
88
90
|
this.emit('success', `Connect to MELCloud Success.`)
|
|
@@ -144,6 +146,7 @@ class MelCloud extends EventEmitter {
|
|
|
144
146
|
];
|
|
145
147
|
|
|
146
148
|
//add all devices to the devices array
|
|
149
|
+
devices.useFahrenheit = this.useFahrenheit;
|
|
147
150
|
devices.push(...allDevices);
|
|
148
151
|
}
|
|
149
152
|
|
|
@@ -152,18 +155,10 @@ class MelCloud extends EventEmitter {
|
|
|
152
155
|
this.emit('warn', `No devices found.`);
|
|
153
156
|
return;
|
|
154
157
|
}
|
|
155
|
-
const debug3 = this.enableDebugMode ? this.emit('debug', `Found: ${devicesCount} devices.`) : false;
|
|
156
|
-
|
|
157
|
-
//get device info fom devices
|
|
158
|
-
for (const deviceInfo of devices) {
|
|
159
|
-
const deviceId = deviceInfo.DeviceID
|
|
160
|
-
const deviceName = deviceInfo.DeviceName;
|
|
161
158
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const debug = this.enableDebugMode ? this.emit('debug', `Device: ${deviceName} info saved.`) : false;
|
|
166
|
-
};
|
|
159
|
+
//save buildings to the file
|
|
160
|
+
await this.saveData(this.devicesFile, devices);
|
|
161
|
+
const debug3 = this.enableDebugMode ? this.emit('debug', `${devicesCount} devices saved.`) : false;
|
|
167
162
|
|
|
168
163
|
return devices;
|
|
169
164
|
} catch (error) {
|
package/src/melcloudata.js
CHANGED
|
@@ -11,8 +11,9 @@ class MelCloudAta extends EventEmitter {
|
|
|
11
11
|
constructor(config) {
|
|
12
12
|
super();
|
|
13
13
|
const contextKey = config.contextKey;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const accountFile = config.accountFile;
|
|
15
|
+
const devicesFile = config.devicesFile;
|
|
16
|
+
const deviceId = config.deviceId;
|
|
16
17
|
const debugLog = config.debugLog;
|
|
17
18
|
const refreshInterval = config.refreshInterval;
|
|
18
19
|
|
|
@@ -39,7 +40,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
39
40
|
impulseGenerator.on('checkDevice', async () => {
|
|
40
41
|
try {
|
|
41
42
|
//read account info from file
|
|
42
|
-
const accountInfo = await this.readData(
|
|
43
|
+
const accountInfo = await this.readData(accountFile);
|
|
43
44
|
|
|
44
45
|
//remove sensitive data
|
|
45
46
|
const debugData = {
|
|
@@ -56,8 +57,9 @@ class MelCloudAta extends EventEmitter {
|
|
|
56
57
|
this.useFahrenheit = useFahrenheit;
|
|
57
58
|
|
|
58
59
|
//read device info from file
|
|
59
|
-
const
|
|
60
|
-
const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(
|
|
60
|
+
const devicesData = await this.readData(devicesFile);
|
|
61
|
+
const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
|
|
62
|
+
const deviceData = devicesData.find((device) => device.DeviceID === deviceId);
|
|
61
63
|
|
|
62
64
|
if (!deviceData) {
|
|
63
65
|
this.emit('warn', `Device data not found.`);
|
|
@@ -65,7 +67,6 @@ class MelCloudAta extends EventEmitter {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
//device info
|
|
68
|
-
const deviceId = deviceData.DeviceID.toString();
|
|
69
70
|
const deviceName = deviceData.DeviceName;
|
|
70
71
|
const buildingId = deviceData.BuildingID;
|
|
71
72
|
const buildingName = deviceData.BuildingName;
|
|
@@ -413,7 +414,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
413
414
|
|
|
414
415
|
await this.axiosInstancePost(CONSTANTS.ApiUrls.SetAta, options);
|
|
415
416
|
this.emit('deviceState', this.deviceData, deviceState, this.useFahrenheit);
|
|
416
|
-
return true
|
|
417
|
+
return true;
|
|
417
418
|
} catch (error) {
|
|
418
419
|
throw new Error(error.message ?? error);
|
|
419
420
|
};
|
package/src/melcloudatw.js
CHANGED
|
@@ -11,8 +11,9 @@ class MelCloudAtw extends EventEmitter {
|
|
|
11
11
|
constructor(config) {
|
|
12
12
|
super();
|
|
13
13
|
const contextKey = config.contextKey;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const accountFile = config.accountFile;
|
|
15
|
+
const devicesFile = config.devicesFile;
|
|
16
|
+
const deviceId = config.deviceId;
|
|
16
17
|
const debugLog = config.debugLog;
|
|
17
18
|
const refreshInterval = config.refreshInterval;
|
|
18
19
|
|
|
@@ -39,7 +40,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
39
40
|
impulseGenerator.on('checkDevice', async () => {
|
|
40
41
|
try {
|
|
41
42
|
//read account info from file
|
|
42
|
-
const accountInfo = await this.readData(
|
|
43
|
+
const accountInfo = await this.readData(accountFile);
|
|
43
44
|
|
|
44
45
|
//remove sensitive data
|
|
45
46
|
const debugData = {
|
|
@@ -56,8 +57,9 @@ class MelCloudAtw extends EventEmitter {
|
|
|
56
57
|
this.useFahrenheit = useFahrenheit;
|
|
57
58
|
|
|
58
59
|
//read device info from file
|
|
59
|
-
const
|
|
60
|
-
const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(
|
|
60
|
+
const devicesData = await this.readData(devicesFile);
|
|
61
|
+
const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
|
|
62
|
+
const deviceData = devicesData.find((device) => device.DeviceID === deviceId);
|
|
61
63
|
|
|
62
64
|
if (!deviceData) {
|
|
63
65
|
this.emit('warn', `Device data not found.`);
|
|
@@ -65,7 +67,6 @@ class MelCloudAtw extends EventEmitter {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
//device info
|
|
68
|
-
const deviceId = deviceData.DeviceID.toString();
|
|
69
70
|
const deviceName = deviceData.DeviceName;
|
|
70
71
|
const buildingId = deviceData.BuildingID;
|
|
71
72
|
const buildingName = deviceData.BuildingName;
|
package/src/melclouderv.js
CHANGED
|
@@ -11,8 +11,9 @@ class MelCloudErv extends EventEmitter {
|
|
|
11
11
|
constructor(config) {
|
|
12
12
|
super();
|
|
13
13
|
const contextKey = config.contextKey;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const accountFile = config.accountFile;
|
|
15
|
+
const devicesFile = config.devicesFile;
|
|
16
|
+
const deviceId = config.deviceId;
|
|
16
17
|
const debugLog = config.debugLog;
|
|
17
18
|
const refreshInterval = config.refreshInterval;
|
|
18
19
|
|
|
@@ -39,7 +40,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
39
40
|
impulseGenerator.on('checkDevice', async () => {
|
|
40
41
|
try {
|
|
41
42
|
//read account info from file
|
|
42
|
-
const accountInfo = await this.readData(
|
|
43
|
+
const accountInfo = await this.readData(accountFile);
|
|
43
44
|
|
|
44
45
|
//remove sensitive data
|
|
45
46
|
const debugData = {
|
|
@@ -56,8 +57,9 @@ class MelCloudErv extends EventEmitter {
|
|
|
56
57
|
this.useFahrenheit = useFahrenheit;
|
|
57
58
|
|
|
58
59
|
//read device info from file
|
|
59
|
-
const
|
|
60
|
-
const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(
|
|
60
|
+
const devicesData = await this.readData(devicesFile);
|
|
61
|
+
const debug1 = debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
|
|
62
|
+
const deviceData = devicesData.find((device) => device.DeviceID === deviceId);
|
|
61
63
|
|
|
62
64
|
if (!deviceData) {
|
|
63
65
|
this.emit('warn', `Device data not found.`);
|
|
@@ -65,7 +67,6 @@ class MelCloudErv extends EventEmitter {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
//deviceData
|
|
68
|
-
const deviceId = deviceData.DeviceID.toString();
|
|
69
70
|
const deviceName = deviceData.DeviceName;
|
|
70
71
|
const buildingId = deviceData.BuildingID;
|
|
71
72
|
const buildingName = deviceData.BuildingName;
|