homebridge-melcloud-control 4.3.0-beta.25 → 4.3.0-beta.27
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/constants.js +2 -1
- package/src/melcloudata.js +15 -5
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.0-beta.
|
|
4
|
+
"version": "4.3.0-beta.27",
|
|
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/constants.js
CHANGED
|
@@ -43,7 +43,8 @@ export const ApiUrlsHome = {
|
|
|
43
43
|
PutDeviceSettings: "https://melcloudhome.com/dashboard",
|
|
44
44
|
PutScheduleEnabled: "https://melcloudhome.com/ata/deviceid/schedule",
|
|
45
45
|
},
|
|
46
|
-
Origin: "https://melcloudhome.com"
|
|
46
|
+
Origin: "https://melcloudhome.com",
|
|
47
|
+
WebSocketURL: "wss://ws.melcloudhome.com/?hash="
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
export const DeviceType = [
|
package/src/melcloudata.js
CHANGED
|
@@ -84,10 +84,8 @@ class MelCloudAta extends EventEmitter {
|
|
|
84
84
|
if (this.connecting || this.socketConnected) return;
|
|
85
85
|
|
|
86
86
|
this.connecting = true;
|
|
87
|
-
const url = `wss://ws.melcloudhome.com/?hash=${deviceData.WsHeaders.hash}`;
|
|
88
|
-
|
|
89
87
|
try {
|
|
90
|
-
const socket = new WebSocket(
|
|
88
|
+
const socket = new WebSocket(`ApiUrlsHome.WebSocketURL${deviceData.WsHeaders.hash}`, { headers: deviceData.WsHeaders.headers })
|
|
91
89
|
.on('error', (err) => {
|
|
92
90
|
if (this.logDebug) this.emit('debug', `Socket error: ${err}`);
|
|
93
91
|
})
|
|
@@ -99,7 +97,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
99
97
|
this.socket = socket;
|
|
100
98
|
this.socketConnected = true;
|
|
101
99
|
this.connecting = false;
|
|
102
|
-
this.reconnectDelay = 1000;
|
|
100
|
+
this.reconnectDelay = 1000;
|
|
103
101
|
this.emit('success', `Socket Connect Success`);
|
|
104
102
|
|
|
105
103
|
// heartbeat
|
|
@@ -319,6 +317,11 @@ class MelCloudAta extends EventEmitter {
|
|
|
319
317
|
this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
320
318
|
break;
|
|
321
319
|
default:
|
|
320
|
+
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
|
|
321
|
+
if (this.logDebug) this.emit('debug', `Socket not open, cannot send`);
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
|
|
322
325
|
if (displayType === 1 && deviceData.Device.OperationMode === 8) {
|
|
323
326
|
deviceData.Device.SetTemperature = (deviceData.Device.DefaultCoolingSetTemperature + deviceData.Device.DefaultHeatingSetTemperature) / 2;
|
|
324
327
|
|
|
@@ -344,7 +347,14 @@ class MelCloudAta extends EventEmitter {
|
|
|
344
347
|
method = 'PUT';
|
|
345
348
|
path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
|
|
346
349
|
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
347
|
-
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
this.socket.send(JSON.stringify(payload));
|
|
353
|
+
return true;
|
|
354
|
+
} catch (err) {
|
|
355
|
+
if (this.logDebug) this.emit('debug', `Socket send error: ${err}`);
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
348
358
|
}
|
|
349
359
|
|
|
350
360
|
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|