homebridge-melcloud-control 4.2.3-beta.19 → 4.2.3-beta.20
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 +14 -18
- package/src/melcloudhome.js +22 -28
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.3-beta.
|
|
4
|
+
"version": "4.2.3-beta.20",
|
|
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
|
@@ -19,7 +19,8 @@ class MelCloud extends EventEmitter {
|
|
|
19
19
|
this.accountFile = accountFile;
|
|
20
20
|
this.buildingsFile = buildingsFile;
|
|
21
21
|
this.devicesFile = devicesFile;
|
|
22
|
-
this.
|
|
22
|
+
this.headers = {};
|
|
23
|
+
|
|
23
24
|
this.functions = new Functions(this.logWarn, this.logError, this.logDebug)
|
|
24
25
|
.on('warn', warn => this.emit('warn', warn))
|
|
25
26
|
.on('error', error => this.emit('error', error))
|
|
@@ -61,17 +62,12 @@ class MelCloud extends EventEmitter {
|
|
|
61
62
|
async checkDevicesList() {
|
|
62
63
|
try {
|
|
63
64
|
const devicesList = { State: false, Info: null, Devices: [] }
|
|
64
|
-
const headers = {
|
|
65
|
-
'X-MitsContextKey': this.contextKey,
|
|
66
|
-
'Content-Type': 'application/json'
|
|
67
|
-
}
|
|
68
|
-
|
|
69
65
|
if (this.logDebug) this.emit('debug', `Scanning for devices...`);
|
|
70
66
|
const listDevicesData = await axios(ApiUrls.ListDevices, {
|
|
71
67
|
method: 'GET',
|
|
72
68
|
baseURL: ApiUrls.BaseURL,
|
|
73
69
|
timeout: 15000,
|
|
74
|
-
headers: headers
|
|
70
|
+
headers: this.headers
|
|
75
71
|
});
|
|
76
72
|
|
|
77
73
|
if (!listDevicesData || !listDevicesData.data) {
|
|
@@ -138,7 +134,7 @@ class MelCloud extends EventEmitter {
|
|
|
138
134
|
if (this.logDebug) this.emit('debug', `Connecting to MELCloud`);
|
|
139
135
|
|
|
140
136
|
try {
|
|
141
|
-
const accountInfo = { State: false, Info: '', LoginData: null,
|
|
137
|
+
const accountInfo = { State: false, Info: '', LoginData: null, Headers: {}, UseFahrenheit: false }
|
|
142
138
|
|
|
143
139
|
const payload = {
|
|
144
140
|
Email: this.user,
|
|
@@ -174,12 +170,16 @@ class MelCloud extends EventEmitter {
|
|
|
174
170
|
accountInfo.Info = 'Context key missing'
|
|
175
171
|
return accountInfo;
|
|
176
172
|
}
|
|
177
|
-
|
|
173
|
+
|
|
174
|
+
this.headers = {
|
|
175
|
+
'X-MitsContextKey': contextKey,
|
|
176
|
+
'Content-Type': 'application/json'
|
|
177
|
+
};
|
|
178
178
|
|
|
179
179
|
accountInfo.State = true;
|
|
180
180
|
accountInfo.Info = 'Connect to MELCloud Success';
|
|
181
181
|
accountInfo.LoginData = loginData;
|
|
182
|
-
accountInfo.
|
|
182
|
+
accountInfo.Headers = this.headers;
|
|
183
183
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
184
184
|
|
|
185
185
|
return accountInfo
|
|
@@ -190,18 +190,14 @@ class MelCloud extends EventEmitter {
|
|
|
190
190
|
|
|
191
191
|
async send(accountInfo) {
|
|
192
192
|
try {
|
|
193
|
-
const
|
|
193
|
+
const payload = { data: accountInfo.LoginData };
|
|
194
|
+
await axios(ApiUrls.UpdateApplicationOptions, {
|
|
194
195
|
method: 'POST',
|
|
195
196
|
baseURL: ApiUrls.BaseURL,
|
|
196
197
|
timeout: 15000,
|
|
197
|
-
headers:
|
|
198
|
-
|
|
199
|
-
'content-type': 'application/json'
|
|
200
|
-
}
|
|
198
|
+
headers: accountInfo.Headers,
|
|
199
|
+
data: payload
|
|
201
200
|
});
|
|
202
|
-
|
|
203
|
-
const payload = { data: accountInfo.LoginData };
|
|
204
|
-
await axiosInstance(ApiUrls.UpdateApplicationOptions, payload);
|
|
205
201
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
206
202
|
return true;
|
|
207
203
|
} catch (error) {
|
package/src/melcloudhome.js
CHANGED
|
@@ -22,7 +22,8 @@ class MelCloud extends EventEmitter {
|
|
|
22
22
|
this.accountFile = accountFile;
|
|
23
23
|
this.buildingsFile = buildingsFile;
|
|
24
24
|
this.devicesFile = devicesFile;
|
|
25
|
-
this.
|
|
25
|
+
this.headers = {};
|
|
26
|
+
|
|
26
27
|
this.functions = new Functions(this.logWarn, this.logError, this.logDebug)
|
|
27
28
|
.on('warn', warn => this.emit('warn', warn))
|
|
28
29
|
.on('error', error => this.emit('error', error))
|
|
@@ -64,25 +65,12 @@ class MelCloud extends EventEmitter {
|
|
|
64
65
|
async checkDevicesList() {
|
|
65
66
|
try {
|
|
66
67
|
const devicesList = { State: false, Info: null, Devices: [] }
|
|
67
|
-
const headers = {
|
|
68
|
-
'Accept': '*/*',
|
|
69
|
-
'Accept-Encoding': 'gzip, deflate, br',
|
|
70
|
-
'Accept-Language': LanguageLocaleMap[this.language],
|
|
71
|
-
'Cookie': this.contextKey,
|
|
72
|
-
'Priority': 'u=3, i',
|
|
73
|
-
'Referer': ApiUrlsHome.Dashboard,
|
|
74
|
-
'Sec-Fetch-Dest': 'empty',
|
|
75
|
-
'Sec-Fetch-Mode': 'cors',
|
|
76
|
-
'Sec-Fetch-Site': 'same-origin',
|
|
77
|
-
'x-csrf': '1'
|
|
78
|
-
};
|
|
79
|
-
|
|
80
68
|
if (this.logDebug) this.emit('debug', `Scanning for devices`);
|
|
81
69
|
const listDevicesData = await axios(ApiUrlsHome.GetUserContext, {
|
|
82
70
|
method: 'GET',
|
|
83
71
|
baseURL: ApiUrlsHome.BaseURL,
|
|
84
72
|
timeout: 25000,
|
|
85
|
-
headers: headers
|
|
73
|
+
headers: this.headers
|
|
86
74
|
});
|
|
87
75
|
const buildingsList = listDevicesData.data.buildings;
|
|
88
76
|
if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
|
|
@@ -161,7 +149,7 @@ class MelCloud extends EventEmitter {
|
|
|
161
149
|
DeviceName: GivenDisplayName,
|
|
162
150
|
SerialNumber: Id,
|
|
163
151
|
Device: deviceObject,
|
|
164
|
-
Headers: headers
|
|
152
|
+
Headers: this.headers
|
|
165
153
|
};
|
|
166
154
|
};
|
|
167
155
|
|
|
@@ -202,7 +190,7 @@ class MelCloud extends EventEmitter {
|
|
|
202
190
|
|
|
203
191
|
let browser;
|
|
204
192
|
try {
|
|
205
|
-
const accountInfo = { State: false, Info: '',
|
|
193
|
+
const accountInfo = { State: false, Info: '', Headers: {}, UseFahrenheit: false };
|
|
206
194
|
let chromiumPath = await this.functions.ensureChromiumInstalled();
|
|
207
195
|
|
|
208
196
|
// === Fallback to Puppeteer's built-in Chromium ===
|
|
@@ -314,16 +302,28 @@ class MelCloud extends EventEmitter {
|
|
|
314
302
|
return accountInfo;
|
|
315
303
|
}
|
|
316
304
|
|
|
317
|
-
const
|
|
305
|
+
const cookies = [
|
|
318
306
|
'__Secure-monitorandcontrol=chunks-2',
|
|
319
307
|
`__Secure-monitorandcontrolC1=${c1}`,
|
|
320
308
|
`__Secure-monitorandcontrolC2=${c2}`
|
|
321
309
|
].join('; ');
|
|
322
|
-
|
|
310
|
+
|
|
311
|
+
this.headers = {
|
|
312
|
+
'Accept': '*/*',
|
|
313
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
314
|
+
'Accept-Language': LanguageLocaleMap[this.language],
|
|
315
|
+
'Cookie': cookies,
|
|
316
|
+
'Priority': 'u=3, i',
|
|
317
|
+
'Referer': ApiUrlsHome.Dashboard,
|
|
318
|
+
'Sec-Fetch-Dest': 'empty',
|
|
319
|
+
'Sec-Fetch-Mode': 'cors',
|
|
320
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
321
|
+
'x-csrf': '1'
|
|
322
|
+
};
|
|
323
323
|
|
|
324
324
|
accountInfo.State = true;
|
|
325
325
|
accountInfo.Info = 'Connect to MELCloud Home Success';
|
|
326
|
-
accountInfo.
|
|
326
|
+
accountInfo.Headers = this.headers;
|
|
327
327
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
328
328
|
|
|
329
329
|
return accountInfo;
|
|
@@ -341,18 +341,12 @@ class MelCloud extends EventEmitter {
|
|
|
341
341
|
|
|
342
342
|
async send(accountInfo) {
|
|
343
343
|
try {
|
|
344
|
-
|
|
344
|
+
await axios(ApiUrlsHome.UpdateApplicationOptions, {
|
|
345
345
|
method: 'POST',
|
|
346
346
|
baseURL: ApiUrlsHome.BaseURL,
|
|
347
347
|
timeout: 15000,
|
|
348
|
-
headers:
|
|
349
|
-
'X-MitsContextKey': accountInfo.ContextKey,
|
|
350
|
-
'content-type': 'application/json'
|
|
351
|
-
}
|
|
348
|
+
headers: accountInfo.Headers
|
|
352
349
|
});
|
|
353
|
-
|
|
354
|
-
const payload = { data: accountInfo.LoginData };
|
|
355
|
-
await axiosInstance(ApiUrlsHome.UpdateApplicationOptions, payload);
|
|
356
350
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
357
351
|
return true;
|
|
358
352
|
} catch (error) {
|