homebridge-melcloud-control 4.3.5-beta.14 → 4.3.5-beta.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/package.json +1 -1
- package/src/melcloudata.js +60 -65
- package/src/melcloudhome.js +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.3.5-beta.
|
|
4
|
+
"version": "4.3.5-beta.16",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
package/src/melcloudata.js
CHANGED
|
@@ -25,86 +25,81 @@ class MelCloudAta extends EventEmitter {
|
|
|
25
25
|
//set default values
|
|
26
26
|
this.deviceData = {};
|
|
27
27
|
this.headers = {};
|
|
28
|
-
this.
|
|
28
|
+
this.firstRun = true;
|
|
29
29
|
|
|
30
30
|
let deviceData = null;
|
|
31
31
|
melcloud.on('devicesList', async (devicesData) => {
|
|
32
32
|
this.headers = devicesData.Headers;
|
|
33
|
-
const webSocket = devicesData.
|
|
33
|
+
const webSocket = devicesData.WebSocket;
|
|
34
34
|
deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
35
35
|
if (!deviceData) return;
|
|
36
36
|
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
//update state
|
|
39
|
+
await this.updateState(deviceData);
|
|
40
|
+
})
|
|
41
|
+
.on('message', async (message) => {
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
43
|
+
const parsedMessage = JSON.parse(message);
|
|
44
|
+
const stringifyMessage = JSON.stringify(parsedMessage, null, 2);
|
|
45
|
+
if (parsedMessage.message === 'Forbidden') return;
|
|
46
|
+
|
|
47
|
+
const messageData = parsedMessage?.[0]?.Data;
|
|
48
|
+
if (!messageData || !deviceData) return;
|
|
49
|
+
|
|
50
|
+
let updateState = false;
|
|
51
|
+
const unitId = messageData?.id;
|
|
52
|
+
switch (unitId) {
|
|
53
|
+
case this.deviceId:
|
|
54
|
+
if (!this.logDebug) this.emit('debug', `Incoming message: ${stringifyMessage}`);
|
|
55
|
+
const messageType = parsedMessage[0].messageType;
|
|
56
|
+
const settings = this.functions.parseArrayNameValue(messageData.settings);
|
|
57
|
+
switch (messageType) {
|
|
58
|
+
case 'unitStateChanged':
|
|
59
|
+
|
|
60
|
+
//update values
|
|
61
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
62
|
+
if (!this.functions.isValidValue(value)) continue;
|
|
63
|
+
|
|
64
|
+
//update holiday mode
|
|
65
|
+
if (key === 'HolidayMode') {
|
|
66
|
+
deviceData.HolidayMode.Enabled = value;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
70
|
+
//update device settings
|
|
71
|
+
if (key in deviceData.Device) {
|
|
72
|
+
deviceData.Device[key] = value;
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
}
|
|
75
|
+
updateState = true;
|
|
76
|
+
break;
|
|
77
|
+
case 'unitHolidayModeTriggered':
|
|
78
|
+
deviceData.Device.Power = settings.Power;
|
|
79
|
+
deviceData.HolidayMode.Enabled = settings.HolidayMode;
|
|
80
|
+
deviceData.HolidayMode.Active = messageData.active;
|
|
81
|
+
updateState = true;
|
|
82
|
+
break;
|
|
83
|
+
case 'unitWifiSignalChanged':
|
|
84
|
+
deviceData.Rssi = messageData.rssi;
|
|
85
|
+
updateState = true;
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${stringifyMessage}`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${stringifyMessage}`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
97
|
+
//update state
|
|
98
|
+
if (updateState) await this.updateState(deviceData);
|
|
100
99
|
} catch (error) {
|
|
101
100
|
if (this.logError) this.emit('error', `Socket connection failed: ${error}`);
|
|
102
101
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//update state
|
|
106
|
-
await this.updateState(deviceData);
|
|
107
|
-
});
|
|
102
|
+
});
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
async updateState(deviceData) {
|
package/src/melcloudhome.js
CHANGED
|
@@ -254,6 +254,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
254
254
|
const parsedMessage = JSON.parse(message);
|
|
255
255
|
const stringifyMessage = JSON.stringify(parsedMessage, null, 2);
|
|
256
256
|
if (this.logDebug) this.emit('debug', `Incoming message: ${stringifyMessage}`);
|
|
257
|
+
this.emit('message', message);
|
|
257
258
|
});
|
|
258
259
|
} catch (error) {
|
|
259
260
|
if (this.logError) this.emit('error', `Socket connection failed: ${error}`);
|
|
@@ -266,7 +267,6 @@ class MelCloudHome extends EventEmitter {
|
|
|
266
267
|
devicesList.Devices = devices;
|
|
267
268
|
devicesList.Scenes = scenes;
|
|
268
269
|
devicesList.Headers = this.headers;
|
|
269
|
-
devicesList.WebSocket = this.socket;
|
|
270
270
|
this.emit('devicesList', devicesList);
|
|
271
271
|
|
|
272
272
|
await this.functions.saveData(this.devicesFile, devicesList);
|