homebridge-melcloud-control 4.2.5-beta.5 → 4.2.5-beta.7
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 +9 -15
- package/src/melcloudata.js +13 -21
- package/src/melcloudatw.js +8 -17
- package/src/melclouderv.js +8 -17
- package/src/melcloudhome.js +11 -21
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.2.5-beta.
|
|
4
|
+
"version": "4.2.5-beta.7",
|
|
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
|
@@ -57,12 +57,7 @@ class MelCloud extends EventEmitter {
|
|
|
57
57
|
try {
|
|
58
58
|
const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
|
|
59
59
|
if (this.logDebug) this.emit('debug', `Scanning for devices...`);
|
|
60
|
-
const listDevicesData = await
|
|
61
|
-
method: 'GET',
|
|
62
|
-
baseURL: ApiUrls.BaseURL,
|
|
63
|
-
timeout: 15000,
|
|
64
|
-
headers: this.headers
|
|
65
|
-
});
|
|
60
|
+
const listDevicesData = await this.axiosInstance(ApiUrls.ListDevices, { method: 'GET', });
|
|
66
61
|
|
|
67
62
|
if (!listDevicesData || !listDevicesData.data) {
|
|
68
63
|
devicesList.Info = 'Invalid or empty response from MELCloud API'
|
|
@@ -168,15 +163,20 @@ class MelCloud extends EventEmitter {
|
|
|
168
163
|
return accountInfo;
|
|
169
164
|
}
|
|
170
165
|
|
|
171
|
-
|
|
166
|
+
const headers = {
|
|
172
167
|
'X-MitsContextKey': contextKey,
|
|
173
168
|
'Content-Type': 'application/json'
|
|
174
169
|
};
|
|
170
|
+
this.headers = headers;
|
|
171
|
+
this.axiosInstance = axios.create({
|
|
172
|
+
baseURL: ApiUrls.BaseURL,
|
|
173
|
+
timeout: 30000,
|
|
174
|
+
headers: headers
|
|
175
|
+
});
|
|
175
176
|
|
|
176
177
|
accountInfo.State = true;
|
|
177
178
|
accountInfo.Info = 'Connect to MELCloud Success';
|
|
178
179
|
accountInfo.LoginData = loginData;
|
|
179
|
-
accountInfo.Headers = this.headers;
|
|
180
180
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
181
181
|
|
|
182
182
|
return accountInfo
|
|
@@ -188,13 +188,7 @@ class MelCloud extends EventEmitter {
|
|
|
188
188
|
async send(accountInfo) {
|
|
189
189
|
try {
|
|
190
190
|
const payload = { data: accountInfo.LoginData };
|
|
191
|
-
await
|
|
192
|
-
method: 'POST',
|
|
193
|
-
baseURL: ApiUrls.BaseURL,
|
|
194
|
-
timeout: 15000,
|
|
195
|
-
headers: accountInfo.Headers,
|
|
196
|
-
data: payload
|
|
197
|
-
});
|
|
191
|
+
await this.axiosInstance(ApiUrls.UpdateApplicationOptions, { method: 'POST', data: payload });
|
|
198
192
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
199
193
|
return true;
|
|
200
194
|
} catch (error) {
|
package/src/melcloudata.js
CHANGED
|
@@ -23,7 +23,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
23
23
|
|
|
24
24
|
//set default values
|
|
25
25
|
this.deviceData = {};
|
|
26
|
-
this.
|
|
26
|
+
this.baseURL = this.accountType === 'melcloud' ? ApiUrls.BaseURL : ApiUrlsHome.BaseURL;
|
|
27
27
|
|
|
28
28
|
//lock flag
|
|
29
29
|
this.locks = true;
|
|
@@ -53,9 +53,13 @@ class MelCloudAta extends EventEmitter {
|
|
|
53
53
|
try {
|
|
54
54
|
//read device info from file
|
|
55
55
|
const devicesData = await this.functions.readData(this.devicesFile, true);
|
|
56
|
-
this.
|
|
57
|
-
|
|
56
|
+
this.axiosInstance = axios.create({
|
|
57
|
+
baseURL: this.baseURL,
|
|
58
|
+
timeout: 30000,
|
|
59
|
+
headers: devicesData.Headers
|
|
60
|
+
});
|
|
58
61
|
|
|
62
|
+
const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
59
63
|
if (this.accountType === 'melcloudhome') {
|
|
60
64
|
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
61
65
|
deviceData.Device.OperationMode = AirConditioner.OperationModeMapStringToEnum[deviceData.Device.OperationMode] ?? deviceData.Device.OperationMode;
|
|
@@ -162,13 +166,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
162
166
|
};
|
|
163
167
|
|
|
164
168
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
|
|
165
|
-
await
|
|
166
|
-
method: 'POST',
|
|
167
|
-
baseURL: ApiUrls.BaseURL,
|
|
168
|
-
timeout: 10000,
|
|
169
|
-
headers: this.headers,
|
|
170
|
-
data: payload
|
|
171
|
-
});
|
|
169
|
+
await this.axiosInstance(path, { method: 'POST', data: payload });
|
|
172
170
|
this.updateData(deviceData);
|
|
173
171
|
return true;
|
|
174
172
|
case "melcloudhome":
|
|
@@ -228,7 +226,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
228
226
|
method = 'PUT';
|
|
229
227
|
const state = flagData.Enabled ? 'Enable' : 'Disable';
|
|
230
228
|
path = ApiUrlsHome.PutScene[state].replace('sceneid', flagData.Id);
|
|
231
|
-
this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
229
|
+
//this.headers.Referer = ApiUrlsHome.Referers.GetPutScenes;
|
|
232
230
|
break;
|
|
233
231
|
default:
|
|
234
232
|
payload = {
|
|
@@ -243,20 +241,14 @@ class MelCloudAta extends EventEmitter {
|
|
|
243
241
|
};
|
|
244
242
|
method = 'PUT';
|
|
245
243
|
path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
|
|
246
|
-
this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
244
|
+
//this.headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings;
|
|
247
245
|
break
|
|
248
246
|
}
|
|
249
247
|
|
|
250
|
-
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
251
|
-
this.headers.Origin = ApiUrlsHome.Origin;
|
|
248
|
+
//this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
249
|
+
//this.headers.Origin = ApiUrlsHome.Origin;
|
|
252
250
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
|
|
253
|
-
await
|
|
254
|
-
method: method,
|
|
255
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
256
|
-
timeout: 10000,
|
|
257
|
-
headers: this.headers,
|
|
258
|
-
data: payload
|
|
259
|
-
});
|
|
251
|
+
await this.axiosInstance(path, { method: method, data: payload });
|
|
260
252
|
this.updateData(deviceData);
|
|
261
253
|
return true;
|
|
262
254
|
default:
|
package/src/melcloudatw.js
CHANGED
|
@@ -23,7 +23,6 @@ class MelCloudAtw extends EventEmitter {
|
|
|
23
23
|
|
|
24
24
|
//set default values
|
|
25
25
|
this.devicesData = {};
|
|
26
|
-
this.headers = {};
|
|
27
26
|
|
|
28
27
|
//lock flags
|
|
29
28
|
this.locks = true;
|
|
@@ -53,9 +52,13 @@ class MelCloudAtw extends EventEmitter {
|
|
|
53
52
|
try {
|
|
54
53
|
//read device info from file
|
|
55
54
|
const devicesData = await this.functions.readData(this.devicesFile, true);
|
|
56
|
-
this.
|
|
57
|
-
|
|
55
|
+
this.axiosInstance = axios.create({
|
|
56
|
+
baseURL: this.baseURL,
|
|
57
|
+
timeout: 30000,
|
|
58
|
+
headers: devicesData.Headers
|
|
59
|
+
});
|
|
58
60
|
|
|
61
|
+
const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
59
62
|
if (this.accountType === 'melcloudhome') {
|
|
60
63
|
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
61
64
|
}
|
|
@@ -168,13 +171,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
|
|
171
|
-
await
|
|
172
|
-
method: 'POST',
|
|
173
|
-
baseURL: ApiUrls.BaseURL,
|
|
174
|
-
timeout: 10000,
|
|
175
|
-
headers: this.headers,
|
|
176
|
-
data: payload
|
|
177
|
-
});
|
|
174
|
+
await this.axiosInstance(path, { method: 'POST', data: payload });
|
|
178
175
|
this.updateData(deviceData);
|
|
179
176
|
return true;
|
|
180
177
|
case "melcloudhome":
|
|
@@ -227,13 +224,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
227
224
|
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
228
225
|
this.headers.Origin = ApiUrlsHome.Origin;
|
|
229
226
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
|
|
230
|
-
await
|
|
231
|
-
method: method,
|
|
232
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
233
|
-
timeout: 10000,
|
|
234
|
-
headers: this.headers,
|
|
235
|
-
data: payload
|
|
236
|
-
});
|
|
227
|
+
await this.axiosInstance(path, { method: method, data: payload });
|
|
237
228
|
this.updateData(deviceData);
|
|
238
229
|
return true;
|
|
239
230
|
default:
|
package/src/melclouderv.js
CHANGED
|
@@ -23,7 +23,6 @@ class MelCloudErv extends EventEmitter {
|
|
|
23
23
|
|
|
24
24
|
//set default values
|
|
25
25
|
this.devicesData = {};
|
|
26
|
-
this.headers = {};
|
|
27
26
|
|
|
28
27
|
//lock flags
|
|
29
28
|
this.locks = true;
|
|
@@ -53,9 +52,13 @@ class MelCloudErv extends EventEmitter {
|
|
|
53
52
|
try {
|
|
54
53
|
//read device info from file
|
|
55
54
|
const devicesData = await this.functions.readData(this.devicesFile, true);
|
|
56
|
-
this.
|
|
57
|
-
|
|
55
|
+
this.axiosInstance = axios.create({
|
|
56
|
+
baseURL: this.baseURL,
|
|
57
|
+
timeout: 30000,
|
|
58
|
+
headers: devicesData.Headers
|
|
59
|
+
});
|
|
58
60
|
|
|
61
|
+
const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
|
|
59
62
|
if (this.accountType === 'melcloudhome') {
|
|
60
63
|
deviceData.Scenes = devicesData.Scenes ?? [];
|
|
61
64
|
|
|
@@ -171,13 +174,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
171
174
|
}
|
|
172
175
|
|
|
173
176
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
|
|
174
|
-
await
|
|
175
|
-
method: 'POST',
|
|
176
|
-
baseURL: ApiUrls.BaseURL,
|
|
177
|
-
timeout: 10000,
|
|
178
|
-
headers: this.headers,
|
|
179
|
-
data: payload
|
|
180
|
-
});
|
|
177
|
+
await this.axiosInstance(path, { method: 'POST', data: payload });
|
|
181
178
|
this.updateData(deviceData);
|
|
182
179
|
return true;
|
|
183
180
|
case "melcloudhome":
|
|
@@ -234,13 +231,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
234
231
|
this.headers['Content-Type'] = 'application/json; charset=utf-8';
|
|
235
232
|
this.headers.Origin = ApiUrlsHome.Origin;
|
|
236
233
|
if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}, Headers: ${JSON.stringify(this.headers, null, 2)}`);
|
|
237
|
-
await
|
|
238
|
-
method: method,
|
|
239
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
240
|
-
timeout: 10000,
|
|
241
|
-
headers: this.headers,
|
|
242
|
-
data: payload
|
|
243
|
-
});
|
|
234
|
+
await this.axiosInstance(path, { method: method, data: payload });
|
|
244
235
|
this.updateData(deviceData);
|
|
245
236
|
return true;
|
|
246
237
|
default:
|
package/src/melcloudhome.js
CHANGED
|
@@ -65,12 +65,7 @@ class MelCloud extends EventEmitter {
|
|
|
65
65
|
async checkScenesList() {
|
|
66
66
|
try {
|
|
67
67
|
if (this.logDebug) this.emit('debug', `Scanning for scenes`);
|
|
68
|
-
const listScenesData = await
|
|
69
|
-
method: 'GET',
|
|
70
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
71
|
-
timeout: 25000,
|
|
72
|
-
headers: this.headers
|
|
73
|
-
});
|
|
68
|
+
const listScenesData = await this.axiosInstance(ApiUrlsHome.GetUserScenes, { method: 'GET', });
|
|
74
69
|
|
|
75
70
|
const scenesList = listScenesData.data;
|
|
76
71
|
if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
|
|
@@ -102,12 +97,7 @@ class MelCloud extends EventEmitter {
|
|
|
102
97
|
try {
|
|
103
98
|
const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
|
|
104
99
|
if (this.logDebug) this.emit('debug', `Scanning for devices`);
|
|
105
|
-
const listDevicesData = await
|
|
106
|
-
method: 'GET',
|
|
107
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
108
|
-
timeout: 25000,
|
|
109
|
-
headers: this.headers
|
|
110
|
-
});
|
|
100
|
+
const listDevicesData = await this.axiosInstance(ApiUrlsHome.GetUserContext, { method: 'GET' });
|
|
111
101
|
|
|
112
102
|
const userContext = listDevicesData.data;
|
|
113
103
|
const buildings = userContext.buildings ?? [];
|
|
@@ -352,7 +342,7 @@ class MelCloud extends EventEmitter {
|
|
|
352
342
|
`__Secure-monitorandcontrolC2=${c2}`
|
|
353
343
|
].join('; ');
|
|
354
344
|
|
|
355
|
-
|
|
345
|
+
const headers = {
|
|
356
346
|
'Accept': '*/*',
|
|
357
347
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
358
348
|
'Accept-Language': LanguageLocaleMap[this.language],
|
|
@@ -364,10 +354,15 @@ class MelCloud extends EventEmitter {
|
|
|
364
354
|
'Sec-Fetch-Site': 'same-origin',
|
|
365
355
|
'x-csrf': '1'
|
|
366
356
|
};
|
|
357
|
+
this.headers = headers;
|
|
358
|
+
this.axiosInstance = axios.create({
|
|
359
|
+
baseURL: ApiUrlsHome.BaseURL,
|
|
360
|
+
timeout: 30000,
|
|
361
|
+
headers: headers
|
|
362
|
+
})
|
|
367
363
|
|
|
368
364
|
accountInfo.State = true;
|
|
369
365
|
accountInfo.Info = 'Connect to MELCloud Home Success';
|
|
370
|
-
accountInfo.Headers = this.headers;
|
|
371
366
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
372
367
|
|
|
373
368
|
return accountInfo;
|
|
@@ -385,13 +380,8 @@ class MelCloud extends EventEmitter {
|
|
|
385
380
|
|
|
386
381
|
async send(accountInfo) {
|
|
387
382
|
try {
|
|
388
|
-
await
|
|
389
|
-
|
|
390
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
391
|
-
timeout: 15000,
|
|
392
|
-
headers: accountInfo.Headers
|
|
393
|
-
});
|
|
394
|
-
await this.functions.saveData(this.accountFile, accountInfo);
|
|
383
|
+
//await this.axiosInstance(ApiUrlsHome.UpdateApplicationOptions, { method: 'POST' });
|
|
384
|
+
//await this.functions.saveData(this.accountFile, accountInfo);
|
|
395
385
|
return true;
|
|
396
386
|
} catch (error) {
|
|
397
387
|
throw new Error(`Send data error: ${error.message}`);
|