homebridge-melcloud-control 4.3.11-beta.25 → 4.3.11-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/melcloud.js +3 -5
- package/src/melcloudata.js +3 -27
- package/src/melcloudatw.js +5 -27
- package/src/melclouderv.js +5 -27
- package/src/melcloudhome.js +19 -26
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.11-beta.
|
|
4
|
+
"version": "4.3.11-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/melcloud.js
CHANGED
|
@@ -17,8 +17,8 @@ class MelCloud extends EventEmitter {
|
|
|
17
17
|
|
|
18
18
|
this.accountFile = accountFile;
|
|
19
19
|
this.buildingsFile = buildingsFile;
|
|
20
|
-
this.headers = {};
|
|
21
20
|
|
|
21
|
+
this.client = null;
|
|
22
22
|
this.functions = new Functions(this.logWarn, this.logError, this.logDebug)
|
|
23
23
|
.on('warn', warn => this.emit('warn', warn))
|
|
24
24
|
.on('error', error => this.emit('error', error))
|
|
@@ -162,15 +162,13 @@ class MelCloud extends EventEmitter {
|
|
|
162
162
|
'X-MitsContextKey': contextKey,
|
|
163
163
|
'Content-Type': 'application/json'
|
|
164
164
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.headers = headers;
|
|
165
|
+
|
|
168
166
|
this.client = axios.create({
|
|
169
167
|
baseURL: ApiUrls.BaseURL,
|
|
170
168
|
timeout: 30000,
|
|
171
169
|
headers: headers
|
|
172
170
|
});
|
|
173
|
-
this.emit('client',
|
|
171
|
+
this.emit('client', this.client);
|
|
174
172
|
|
|
175
173
|
accountInfo.State = true;
|
|
176
174
|
accountInfo.Info = 'Connect Success';
|
package/src/melcloudata.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import EventEmitter from 'events';
|
|
3
2
|
import Functions from './functions.js';
|
|
4
3
|
import { ApiUrls, ApiUrlsHome, AirConditioner } from './constants.js';
|
|
@@ -25,14 +24,11 @@ class MelCloudAta extends EventEmitter {
|
|
|
25
24
|
//set default values
|
|
26
25
|
this.deviceData = {};
|
|
27
26
|
this.client = melcloud.client;
|
|
28
|
-
this.headers = melcloud.headers;
|
|
29
27
|
|
|
30
28
|
//handle melcloud events
|
|
31
29
|
let deviceData = null;
|
|
32
30
|
melcloud.on('client', (client) => {
|
|
33
31
|
this.client = client;
|
|
34
|
-
}).on('headers', (headers) => {
|
|
35
|
-
this.headers = headers;
|
|
36
32
|
}).on('devicesList', async (devicesData) => {
|
|
37
33
|
try {
|
|
38
34
|
deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
@@ -200,7 +196,6 @@ class MelCloudAta extends EventEmitter {
|
|
|
200
196
|
let method = null
|
|
201
197
|
let payload = {};
|
|
202
198
|
let path = '';
|
|
203
|
-
let headers = this.headers;
|
|
204
199
|
switch (accountType) {
|
|
205
200
|
case "melcloud":
|
|
206
201
|
switch (flag) {
|
|
@@ -238,14 +233,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
238
233
|
}
|
|
239
234
|
|
|
240
235
|
if (this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
|
|
241
|
-
|
|
242
|
-
await axios(path, {
|
|
243
|
-
method: 'POST',
|
|
244
|
-
baseURL: ApiUrls.BaseURL,
|
|
245
|
-
timeout: 30000,
|
|
246
|
-
headers: headers,
|
|
247
|
-
data: payload
|
|
248
|
-
});
|
|
236
|
+
await this.client(path, { method: 'POST', data: payload });
|
|
249
237
|
|
|
250
238
|
this.emit('deviceState', deviceData);
|
|
251
239
|
return true;
|
|
@@ -260,7 +248,6 @@ class MelCloudAta extends EventEmitter {
|
|
|
260
248
|
};
|
|
261
249
|
method = 'POST';
|
|
262
250
|
path = ApiUrlsHome.PostProtectionFrost;
|
|
263
|
-
headers.Referer = ApiUrlsHome.Referers.PostProtectionFrost.replace('deviceid', deviceData.DeviceID);
|
|
264
251
|
break;
|
|
265
252
|
case 'overheatprotection':
|
|
266
253
|
payload = {
|
|
@@ -271,7 +258,6 @@ class MelCloudAta extends EventEmitter {
|
|
|
271
258
|
};
|
|
272
259
|
method = 'POST';
|
|
273
260
|
path = ApiUrlsHome.PostProtectionOverheat;
|
|
274
|
-
headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
|
|
275
261
|
break;
|
|
276
262
|
case 'holidaymode':
|
|
277
263
|
payload = {
|
|
@@ -282,18 +268,15 @@ class MelCloudAta extends EventEmitter {
|
|
|
282
268
|
};
|
|
283
269
|
method = 'POST';
|
|
284
270
|
path = ApiUrlsHome.PostHolidayMode;
|
|
285
|
-
headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
286
271
|
break;
|
|
287
272
|
case 'schedule':
|
|
288
273
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
289
274
|
method = 'PUT';
|
|
290
275
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
291
|
-
this.headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
292
276
|
break;
|
|
293
277
|
case 'scene':
|
|
294
278
|
method = 'PUT';
|
|
295
279
|
path = ApiUrlsHome.PutScene[flagData.Enabled ? 'Enable' : 'Disable'].replace('sceneid', flagData.Id);
|
|
296
|
-
headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
297
280
|
break;
|
|
298
281
|
default:
|
|
299
282
|
if (displayType === 1 && deviceData.Device.OperationMode === 8) {
|
|
@@ -320,19 +303,12 @@ class MelCloudAta extends EventEmitter {
|
|
|
320
303
|
};
|
|
321
304
|
method = 'PUT';
|
|
322
305
|
path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
|
|
323
|
-
headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
324
306
|
break;
|
|
325
307
|
}
|
|
326
308
|
|
|
327
|
-
//
|
|
328
|
-
headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
329
|
-
headers.Origin = ApiUrlsHome.Origin;
|
|
309
|
+
//send payload
|
|
330
310
|
if (!this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
|
|
331
|
-
|
|
332
|
-
await this.client(path, {
|
|
333
|
-
method: method,
|
|
334
|
-
data: payload
|
|
335
|
-
});
|
|
311
|
+
await this.client(path, { method: method, data: payload });
|
|
336
312
|
|
|
337
313
|
return true;
|
|
338
314
|
default:
|
package/src/melcloudatw.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import EventEmitter from 'events';
|
|
3
2
|
import Functions from './functions.js';
|
|
4
3
|
import { ApiUrls, ApiUrlsHome, HeatPump } from './constants.js';
|
|
@@ -24,12 +23,12 @@ class MelCloudAtw extends EventEmitter {
|
|
|
24
23
|
|
|
25
24
|
//set default values
|
|
26
25
|
this.deviceData = {};
|
|
27
|
-
this.
|
|
26
|
+
this.client = melcloud.client;
|
|
28
27
|
|
|
29
28
|
//handle melcloud events
|
|
30
29
|
let deviceData = null;
|
|
31
|
-
melcloud.on('
|
|
32
|
-
this.
|
|
30
|
+
melcloud.on('client', (client) => {
|
|
31
|
+
this.client = client;
|
|
33
32
|
}).on('devicesList', async (devicesData) => {
|
|
34
33
|
try {
|
|
35
34
|
deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
@@ -198,7 +197,6 @@ class MelCloudAtw extends EventEmitter {
|
|
|
198
197
|
let method = null
|
|
199
198
|
let payload = {};
|
|
200
199
|
let path = '';
|
|
201
|
-
let headers = this.headers;
|
|
202
200
|
switch (accountType) {
|
|
203
201
|
case "melcloud":
|
|
204
202
|
switch (flag) {
|
|
@@ -237,14 +235,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
if (this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
|
|
240
|
-
|
|
241
|
-
await axios(path, {
|
|
242
|
-
method: 'POST',
|
|
243
|
-
baseURL: ApiUrls.BaseURL,
|
|
244
|
-
timeout: 30000,
|
|
245
|
-
headers: headers,
|
|
246
|
-
data: payload
|
|
247
|
-
});
|
|
238
|
+
await this.client(path, { method: 'POST', data: payload });
|
|
248
239
|
|
|
249
240
|
this.emit('deviceState', deviceData);
|
|
250
241
|
return true;
|
|
@@ -259,18 +250,15 @@ class MelCloudAtw extends EventEmitter {
|
|
|
259
250
|
};
|
|
260
251
|
method = 'POST';
|
|
261
252
|
path = ApiUrlsHome.PostHolidayMode;
|
|
262
|
-
headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
263
253
|
break;
|
|
264
254
|
case 'schedule':
|
|
265
255
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
266
256
|
method = 'PUT';
|
|
267
257
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
268
|
-
headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
269
258
|
break;
|
|
270
259
|
case 'scene':
|
|
271
260
|
method = 'PUT';
|
|
272
261
|
path = ApiUrlsHome.PutScene[flagData.Enabled ? 'Enable' : 'Disable'].replace('sceneid', flagData.Id);
|
|
273
|
-
headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
274
262
|
break;
|
|
275
263
|
default:
|
|
276
264
|
payload = {
|
|
@@ -290,21 +278,11 @@ class MelCloudAtw extends EventEmitter {
|
|
|
290
278
|
};
|
|
291
279
|
method = 'PUT';
|
|
292
280
|
path = ApiUrlsHome.PutAtw.replace('deviceid', deviceData.DeviceID);
|
|
293
|
-
headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
294
281
|
break
|
|
295
282
|
}
|
|
296
283
|
|
|
297
|
-
headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
298
|
-
headers.Origin = ApiUrlsHome.Origin;
|
|
299
284
|
if (this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
|
|
300
|
-
|
|
301
|
-
await axios(path, {
|
|
302
|
-
method: method,
|
|
303
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
304
|
-
timeout: 30000,
|
|
305
|
-
headers: headers,
|
|
306
|
-
data: payload
|
|
307
|
-
});
|
|
285
|
+
await this.client(path, { method: method, data: payload });
|
|
308
286
|
|
|
309
287
|
return true;
|
|
310
288
|
default:
|
package/src/melclouderv.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import EventEmitter from 'events';
|
|
3
2
|
import Functions from './functions.js';
|
|
4
3
|
import { ApiUrls, ApiUrlsHome, Ventilation } from './constants.js';
|
|
@@ -24,12 +23,12 @@ class MelCloudErv extends EventEmitter {
|
|
|
24
23
|
|
|
25
24
|
//set default values
|
|
26
25
|
this.deviceData = {};
|
|
27
|
-
this.
|
|
26
|
+
this.client = melcloud.client;
|
|
28
27
|
|
|
29
28
|
//handle melcloud events
|
|
30
29
|
let deviceData = null;
|
|
31
|
-
melcloud.on('
|
|
32
|
-
this.
|
|
30
|
+
melcloud.on('client', (client) => {
|
|
31
|
+
this.client = client;
|
|
33
32
|
}).on('devicesList', async (devicesData) => {
|
|
34
33
|
try {
|
|
35
34
|
deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
@@ -183,7 +182,6 @@ class MelCloudErv extends EventEmitter {
|
|
|
183
182
|
let method = null
|
|
184
183
|
let payload = {};
|
|
185
184
|
let path = '';
|
|
186
|
-
let headers = this.headers;
|
|
187
185
|
switch (accountType) {
|
|
188
186
|
case "melcloud":
|
|
189
187
|
switch (flag) {
|
|
@@ -237,14 +235,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
if (this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
|
|
240
|
-
|
|
241
|
-
await axios(path, {
|
|
242
|
-
method: 'POST',
|
|
243
|
-
baseURL: ApiUrls.BaseURL,
|
|
244
|
-
timeout: 30000,
|
|
245
|
-
headers: headers,
|
|
246
|
-
data: payload
|
|
247
|
-
});
|
|
238
|
+
await this.client(path, { method: 'POST', data: payload });
|
|
248
239
|
|
|
249
240
|
this.emit('deviceState', deviceData);
|
|
250
241
|
return true;
|
|
@@ -259,18 +250,15 @@ class MelCloudErv extends EventEmitter {
|
|
|
259
250
|
};
|
|
260
251
|
method = 'POST';
|
|
261
252
|
path = ApiUrlsHome.PostHolidayMode;
|
|
262
|
-
headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
263
253
|
break;
|
|
264
254
|
case 'schedule':
|
|
265
255
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
266
256
|
method = 'PUT';
|
|
267
257
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
268
|
-
headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
269
258
|
break;
|
|
270
259
|
case 'scene':
|
|
271
260
|
method = 'PUT';
|
|
272
261
|
path = ApiUrlsHome.PutScene[flagData.Enabled ? 'Enable' : 'Disable'].replace('sceneid', flagData.Id);
|
|
273
|
-
headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
274
262
|
break;
|
|
275
263
|
default:
|
|
276
264
|
if (displayType === 1 && deviceData.Device.VentilationMode === 2) {
|
|
@@ -294,21 +282,11 @@ class MelCloudErv extends EventEmitter {
|
|
|
294
282
|
};
|
|
295
283
|
method = 'PUT';
|
|
296
284
|
path = ApiUrlsHome.PutErv.replace('deviceid', deviceData.DeviceID);
|
|
297
|
-
headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
298
285
|
break
|
|
299
286
|
}
|
|
300
287
|
|
|
301
|
-
headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
302
|
-
headers.Origin = ApiUrlsHome.Origin;
|
|
303
288
|
if (this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
|
|
304
|
-
|
|
305
|
-
await axios(path, {
|
|
306
|
-
method: method,
|
|
307
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
308
|
-
timeout: 30000,
|
|
309
|
-
headers: headers,
|
|
310
|
-
data: payload
|
|
311
|
-
});
|
|
289
|
+
await this.client(path, { method: method, data: payload });
|
|
312
290
|
|
|
313
291
|
return true;
|
|
314
292
|
default:
|
package/src/melcloudhome.js
CHANGED
|
@@ -24,9 +24,8 @@ class MelCloudHome extends EventEmitter {
|
|
|
24
24
|
this.accountFile = accountFile;
|
|
25
25
|
this.buildingsFile = buildingsFile;
|
|
26
26
|
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.socket = null;
|
|
27
|
+
this.client = null;
|
|
28
|
+
this.webSocket = null;
|
|
30
29
|
this.connecting = false;
|
|
31
30
|
this.socketConnected = false;
|
|
32
31
|
this.heartbeat = null;
|
|
@@ -74,9 +73,9 @@ class MelCloudHome extends EventEmitter {
|
|
|
74
73
|
this.heartbeat = null;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
if (this.
|
|
78
|
-
try { this.
|
|
79
|
-
this.
|
|
76
|
+
if (this.webSocket) {
|
|
77
|
+
try { this.webSocket.close(); } catch { }
|
|
78
|
+
this.webSocket = null;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
this.socketConnected = false;
|
|
@@ -216,12 +215,10 @@ class MelCloudHome extends EventEmitter {
|
|
|
216
215
|
this.connecting = true;
|
|
217
216
|
|
|
218
217
|
try {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
this.socket.close();
|
|
224
|
-
})
|
|
218
|
+
this.webSocket.on('error', (error) => {
|
|
219
|
+
if (this.logError) this.emit('error', `Socket error: ${error}`);
|
|
220
|
+
this.socket.close();
|
|
221
|
+
})
|
|
225
222
|
.on('close', () => {
|
|
226
223
|
if (this.logDebug) this.emit('debug', `Socket closed`);
|
|
227
224
|
this.cleanupSocket();
|
|
@@ -331,15 +328,22 @@ class MelCloudHome extends EventEmitter {
|
|
|
331
328
|
page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
|
|
332
329
|
|
|
333
330
|
// === CDP session ===
|
|
334
|
-
let hash = null;
|
|
335
331
|
const client = await page.createCDPSession();
|
|
336
332
|
await client.send('Network.enable')
|
|
337
333
|
client.on('Network.webSocketCreated', ({ url }) => {
|
|
338
334
|
try {
|
|
339
335
|
if (url.startsWith('wss://ws.melcloudhome.com/?hash=')) {
|
|
340
336
|
const params = new URL(url).searchParams;
|
|
341
|
-
hash = params.get('hash');
|
|
337
|
+
const hash = params.get('hash');
|
|
342
338
|
if (this.logDebug) this.emit('debug', `MelCloudHome WS hash detected: ${hash}`);
|
|
339
|
+
|
|
340
|
+
const headers = {
|
|
341
|
+
'Origin': ApiUrlsHome.BaseURL,
|
|
342
|
+
'Pragma': 'no-cache',
|
|
343
|
+
'Cache-Control': 'no-cache'
|
|
344
|
+
};
|
|
345
|
+
const webSocketUrl = `${ApiUrlsHome.WebSocketURL}${hash}`;
|
|
346
|
+
this.webSocket = new WebSocket(webSocketUrl, { headers: headers });
|
|
343
347
|
}
|
|
344
348
|
} catch (error) {
|
|
345
349
|
if (this.logError) this.emit('error', `CDP WebSocketCreated handler error: ${error.message}`);
|
|
@@ -419,24 +423,13 @@ class MelCloudHome extends EventEmitter {
|
|
|
419
423
|
'User-Agent': userAgent,
|
|
420
424
|
'x-csrf': '1'
|
|
421
425
|
};
|
|
422
|
-
this.emit('headers', headers);
|
|
423
426
|
|
|
424
|
-
this.headers = headers;
|
|
425
427
|
this.client = axios.create({
|
|
426
428
|
baseURL: ApiUrlsHome.BaseURL,
|
|
427
429
|
timeout: 30000,
|
|
428
430
|
headers: headers
|
|
429
431
|
})
|
|
430
|
-
this.emit('client',
|
|
431
|
-
|
|
432
|
-
this.webSocketOptions = {
|
|
433
|
-
Hash: hash,
|
|
434
|
-
Headers: {
|
|
435
|
-
'Origin': ApiUrlsHome.BaseURL,
|
|
436
|
-
'Pragma': 'no-cache',
|
|
437
|
-
'Cache-Control': 'no-cache'
|
|
438
|
-
}
|
|
439
|
-
};
|
|
432
|
+
this.emit('client', this.client);
|
|
440
433
|
|
|
441
434
|
accountInfo.State = true;
|
|
442
435
|
accountInfo.Info = 'Connect Success';
|