homebridge-melcloud-control 3.1.10 → 3.1.16
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 +7 -2
- package/README.md +8 -8
- package/homebridge-ui/server.js +1 -3
- package/index.js +4 -3
- package/package.json +2 -2
- package/src/deviceata.js +353 -358
- package/src/deviceatw.js +349 -345
- package/src/deviceerv.js +205 -208
- package/src/melcloud.js +25 -25
- package/src/melcloudata.js +71 -80
- package/src/melcloudatw.js +67 -67
- package/src/melclouderv.js +45 -56
package/src/melclouderv.js
CHANGED
|
@@ -10,14 +10,12 @@ const CONSTANTS = require('./constants.json');
|
|
|
10
10
|
class MelCloudErv extends EventEmitter {
|
|
11
11
|
constructor(config) {
|
|
12
12
|
super();
|
|
13
|
-
this.accountFile = config.accountFile;
|
|
14
13
|
this.devicesFile = config.devicesFile;
|
|
15
14
|
this.deviceId = config.deviceId;
|
|
16
15
|
this.debugLog = config.debugLog;
|
|
17
16
|
|
|
18
17
|
//set default values
|
|
19
|
-
this.
|
|
20
|
-
this.displayDeviceInfo = true;
|
|
18
|
+
this.deviceState = {};
|
|
21
19
|
|
|
22
20
|
this.axiosInstancePost = axios.create({
|
|
23
21
|
method: 'POST',
|
|
@@ -39,41 +37,22 @@ class MelCloudErv extends EventEmitter {
|
|
|
39
37
|
try {
|
|
40
38
|
await this.checkState();
|
|
41
39
|
} catch (error) {
|
|
42
|
-
|
|
43
|
-
this.emit('error', `Impulse generator check state error: ${error.message || error}, check again in 15s.`);
|
|
40
|
+
this.emit('error', `Impulse generator check state error: ${error.message || error}.`);
|
|
44
41
|
};
|
|
45
42
|
}).on('state', (state) => { });
|
|
46
43
|
};
|
|
47
44
|
|
|
48
45
|
async checkState() {
|
|
49
46
|
try {
|
|
50
|
-
//read account info from file
|
|
51
|
-
const accountInfo = await this.readData(this.accountFile);
|
|
52
|
-
|
|
53
|
-
//remove sensitive data
|
|
54
|
-
const debugData = {
|
|
55
|
-
...accountInfo,
|
|
56
|
-
ContextKey: 'removed',
|
|
57
|
-
ClientId: 'removed',
|
|
58
|
-
Client: 'removed',
|
|
59
|
-
Name: 'removed',
|
|
60
|
-
MapLongitude: 'removed',
|
|
61
|
-
MapLatitude: 'removed'
|
|
62
|
-
};
|
|
63
|
-
const debug = this.debugLog ? this.emit('debug', `Account Info: ${JSON.stringify(debugData, null, 2)}`) : false;
|
|
64
|
-
const useFahrenheit = accountInfo.UseFahrenheit ? 1 : 0;
|
|
65
|
-
this.useFahrenheit = useFahrenheit;
|
|
66
|
-
|
|
67
47
|
//read device info from file
|
|
68
48
|
const devicesData = await this.readData(this.devicesFile);
|
|
69
|
-
const debug1 = this.debugLog ? this.emit('debug', `Device Info: ${JSON.stringify(devicesData, null, 2)}`) : false;
|
|
70
49
|
const deviceData = devicesData.find((device) => device.DeviceID === this.deviceId);
|
|
71
50
|
|
|
72
51
|
if (!deviceData) {
|
|
73
|
-
|
|
74
|
-
this.emit('error', `Device data not found, check again in 15s.`);
|
|
52
|
+
this.emit('warn', `Device data not found.`);
|
|
75
53
|
return;
|
|
76
54
|
}
|
|
55
|
+
const debug = this.debugLog ? this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`) : false;
|
|
77
56
|
|
|
78
57
|
//deviceData
|
|
79
58
|
const deviceId = deviceData.DeviceID;
|
|
@@ -317,14 +296,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
317
296
|
this.emit('message', `Units are not configured in MELCloud service.`);
|
|
318
297
|
};
|
|
319
298
|
|
|
320
|
-
//emit info
|
|
321
|
-
const emitInfo = this.displayDeviceInfo ? this.emit('deviceInfo', manufacturer, modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion) : false;
|
|
322
|
-
this.displayDeviceInfo = false;
|
|
323
|
-
|
|
324
|
-
//device state
|
|
325
299
|
const deviceState = {
|
|
326
|
-
DeviceId: deviceId,
|
|
327
|
-
EffectiveFlags: effectiveFlags,
|
|
328
300
|
RoomTemperature: roomTemperature,
|
|
329
301
|
SupplyTemperature: supplyTemperature,
|
|
330
302
|
OutdoorTemperature: outdoorTemperature,
|
|
@@ -333,32 +305,30 @@ class MelCloudErv extends EventEmitter {
|
|
|
333
305
|
SetFanSpeed: setFanSpeed,
|
|
334
306
|
OperationMode: operationMode,
|
|
335
307
|
VentilationMode: ventilationMode,
|
|
336
|
-
DefaultCoolingSetTemperature: defaultCoolingSetTemperature,
|
|
337
|
-
DefaultHeatingSetTemperature: defaultHeatingSetTemperature,
|
|
338
308
|
HideRoomTemperature: hideRoomTemperature,
|
|
339
309
|
HideSupplyTemperature: hideSupplyTemperature,
|
|
340
310
|
HideOutdoorTemperature: hideOutdoorTemperature,
|
|
341
|
-
Power: power
|
|
342
|
-
Offline: offline,
|
|
311
|
+
Power: power
|
|
343
312
|
}
|
|
344
313
|
|
|
345
|
-
//external integrations
|
|
346
|
-
this.emit('externalIntegrations', deviceData, deviceState, deviceId);
|
|
347
|
-
|
|
348
314
|
//check state changes
|
|
349
|
-
const
|
|
350
|
-
if (
|
|
315
|
+
const deviceDataHasNotChanged = JSON.stringify(deviceState) === JSON.stringify(this.deviceState);
|
|
316
|
+
if (deviceDataHasNotChanged) {
|
|
351
317
|
return;
|
|
352
318
|
}
|
|
319
|
+
this.deviceState = deviceState;
|
|
320
|
+
|
|
321
|
+
//external integrations
|
|
322
|
+
this.emit('externalIntegrations', deviceData);
|
|
323
|
+
|
|
324
|
+
//emit info
|
|
325
|
+
this.emit('deviceInfo', manufacturer, modelIndoor, modelOutdoor, serialNumber, firmwareAppVersion);
|
|
353
326
|
|
|
354
327
|
//emit state
|
|
355
|
-
this.
|
|
356
|
-
const debug2 = this.debugLog ? this.emit('debug', `Device State: ${JSON.stringify(deviceState, null, 2)}`) : false;
|
|
357
|
-
this.emit('deviceState', deviceData, deviceState, useFahrenheit);
|
|
328
|
+
this.emit('deviceState', deviceData);
|
|
358
329
|
|
|
359
330
|
return true;
|
|
360
331
|
} catch (error) {
|
|
361
|
-
await this.impulseGenerator.stop();
|
|
362
332
|
throw new Error(`Check state error: ${error.message || error}.`);
|
|
363
333
|
};
|
|
364
334
|
};
|
|
@@ -373,21 +343,40 @@ class MelCloudErv extends EventEmitter {
|
|
|
373
343
|
}
|
|
374
344
|
}
|
|
375
345
|
|
|
376
|
-
async send(
|
|
346
|
+
async send(deviceData) {
|
|
377
347
|
try {
|
|
378
348
|
//prevent to set out of range temp
|
|
379
|
-
const minTemp =
|
|
380
|
-
const maxTemp =
|
|
381
|
-
|
|
382
|
-
|
|
349
|
+
const minTemp = deviceData.Device.MinTempHeat ?? 10;
|
|
350
|
+
const maxTemp = deviceData.Device.MaxTempHeat ?? 31;
|
|
351
|
+
deviceData.Device.SetTemperature = deviceData.Device.SetTemperature < minTemp ? minTemp : deviceData.Device.SetTemperature;
|
|
352
|
+
deviceData.Device.SetTemperature = deviceData.Device.SetTemperature > maxTemp ? maxTemp : deviceData.Device.SetTemperature;
|
|
383
353
|
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
data:
|
|
387
|
-
|
|
354
|
+
//device state
|
|
355
|
+
const payload = {
|
|
356
|
+
data: {
|
|
357
|
+
DeviceID: deviceData.Device.DeviceID,
|
|
358
|
+
EffectiveFlags: deviceData.Device.EffectiveFlags,
|
|
359
|
+
RoomTemperature: deviceData.Device.RoomTemperature,
|
|
360
|
+
SupplyTemperature: deviceData.Device.SupplyTemperature,
|
|
361
|
+
OutdoorTemperature: deviceData.Device.OutdoorTemperature,
|
|
362
|
+
NightPurgeMode: deviceData.Device.NightPurgeMode,
|
|
363
|
+
SetTemperature: deviceData.Device.SetTemperature,
|
|
364
|
+
SetFanSpeed: deviceData.Device.SetFanSpeed,
|
|
365
|
+
OperationMode: deviceData.Device.OperationMode,
|
|
366
|
+
VentilationMode: deviceData.Device.VentilationMode,
|
|
367
|
+
DefaultCoolingSetTemperature: deviceData.Device.DefaultCoolingSetTemperature ?? 23,
|
|
368
|
+
DefaultHeatingSetTemperature: deviceData.Device.DefaultHeatingSetTemperature ?? 21,
|
|
369
|
+
HideRoomTemperature: deviceData.Device.HideRoomTemperature,
|
|
370
|
+
HideSupplyTemperature: deviceData.Device.HideSupplyTemperature,
|
|
371
|
+
HideOutdoorTemperature: deviceData.Device.HideOutdoorTemperature,
|
|
372
|
+
Power: deviceData.Device.Power,
|
|
373
|
+
Offline: deviceData.Device.Offline,
|
|
374
|
+
HasPendingCommand: true
|
|
375
|
+
}
|
|
376
|
+
}
|
|
388
377
|
|
|
389
|
-
await this.axiosInstancePost(CONSTANTS.ApiUrls.SetErv,
|
|
390
|
-
this.emit('deviceState',
|
|
378
|
+
await this.axiosInstancePost(CONSTANTS.ApiUrls.SetErv, payload);
|
|
379
|
+
this.emit('deviceState', deviceData);
|
|
391
380
|
return true;
|
|
392
381
|
} catch (error) {
|
|
393
382
|
throw new Error(error.message ?? error);
|