homebridge-melcloud-control 4.2.5-beta.2 → 4.2.5-beta.21
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/README.md +3 -3
- package/config.schema.json +36 -18
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/constants.js +1 -0
- package/src/deviceata.js +256 -231
- package/src/deviceatw.js +185 -164
- package/src/deviceerv.js +128 -104
- package/src/melcloud.js +10 -17
- package/src/melcloudata.js +19 -27
- package/src/melcloudatw.js +10 -20
- package/src/melclouderv.js +10 -20
- package/src/melcloudhome.js +18 -40
package/src/melcloudhome.js
CHANGED
|
@@ -61,16 +61,10 @@ class MelCloud extends EventEmitter {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// MELCloud Home
|
|
65
64
|
async checkScenesList() {
|
|
66
65
|
try {
|
|
67
66
|
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
|
-
});
|
|
67
|
+
const listScenesData = await this.axiosInstance(ApiUrlsHome.GetUserScenes, { method: 'GET', });
|
|
74
68
|
|
|
75
69
|
const scenesList = listScenesData.data;
|
|
76
70
|
if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
|
|
@@ -102,12 +96,7 @@ class MelCloud extends EventEmitter {
|
|
|
102
96
|
try {
|
|
103
97
|
const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
|
|
104
98
|
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
|
-
});
|
|
99
|
+
const listDevicesData = await this.axiosInstance(ApiUrlsHome.GetUserContext, { method: 'GET' });
|
|
111
100
|
|
|
112
101
|
const userContext = listDevicesData.data;
|
|
113
102
|
const buildings = userContext.buildings ?? [];
|
|
@@ -218,12 +207,6 @@ class MelCloud extends EventEmitter {
|
|
|
218
207
|
|
|
219
208
|
return devicesList;
|
|
220
209
|
} catch (error) {
|
|
221
|
-
if (error.response?.status === 401) {
|
|
222
|
-
if (this.logWarn) this.emit('warn', 'Check devices list not possible, cookies expired, trying to get new.');
|
|
223
|
-
await this.connect();
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
210
|
throw new Error(`Check devices list error: ${error.message}`);
|
|
228
211
|
}
|
|
229
212
|
}
|
|
@@ -234,7 +217,7 @@ class MelCloud extends EventEmitter {
|
|
|
234
217
|
|
|
235
218
|
let browser;
|
|
236
219
|
try {
|
|
237
|
-
const accountInfo = { State: false, Info: '',
|
|
220
|
+
const accountInfo = { State: false, Info: '', UseFahrenheit: false };
|
|
238
221
|
let chromiumPath = await this.functions.ensureChromiumInstalled();
|
|
239
222
|
|
|
240
223
|
// === Fallback to Puppeteer's built-in Chromium ===
|
|
@@ -286,14 +269,6 @@ class MelCloud extends EventEmitter {
|
|
|
286
269
|
page.setDefaultTimeout(GLOBAL_TIMEOUT);
|
|
287
270
|
page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
|
|
288
271
|
|
|
289
|
-
// Clear cookies before navigation
|
|
290
|
-
try {
|
|
291
|
-
const client = await page.createCDPSession();
|
|
292
|
-
await client.send('Network.clearBrowserCookies');
|
|
293
|
-
} catch (error) {
|
|
294
|
-
if (this.logError) this.emit('error', `Clear cookies error: ${error.message}`);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
272
|
try {
|
|
298
273
|
await page.goto(ApiUrlsHome.BaseURL, { waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT });
|
|
299
274
|
} catch (error) {
|
|
@@ -303,7 +278,7 @@ class MelCloud extends EventEmitter {
|
|
|
303
278
|
|
|
304
279
|
// Wait extra to ensure UI is rendered
|
|
305
280
|
await new Promise(r => setTimeout(r, 3000));
|
|
306
|
-
const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT /
|
|
281
|
+
const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT / 3 });
|
|
307
282
|
const loginText = await page.evaluate(el => el.textContent.trim(), loginBtn);
|
|
308
283
|
|
|
309
284
|
if (!['Zaloguj', 'Sign In', 'Login'].includes(loginText)) {
|
|
@@ -329,13 +304,13 @@ class MelCloud extends EventEmitter {
|
|
|
329
304
|
accountInfo.Info = 'Submit button not found';
|
|
330
305
|
return accountInfo;
|
|
331
306
|
}
|
|
332
|
-
await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT /
|
|
307
|
+
await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 3 })]), new Promise(r => setTimeout(r, GLOBAL_TIMEOUT / 3))]);
|
|
333
308
|
|
|
334
309
|
// Extract cookies
|
|
335
310
|
let c1 = null, c2 = null;
|
|
336
311
|
const start = Date.now();
|
|
337
312
|
while ((!c1 || !c2) && Date.now() - start < GLOBAL_TIMEOUT / 2) {
|
|
338
|
-
const cookies = await
|
|
313
|
+
const cookies = await browser.cookies();
|
|
339
314
|
c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || c1;
|
|
340
315
|
c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || c2;
|
|
341
316
|
if (!c1 || !c2) await new Promise(r => setTimeout(r, 500));
|
|
@@ -352,7 +327,9 @@ class MelCloud extends EventEmitter {
|
|
|
352
327
|
`__Secure-monitorandcontrolC2=${c2}`
|
|
353
328
|
].join('; ');
|
|
354
329
|
|
|
355
|
-
|
|
330
|
+
|
|
331
|
+
const userAgent = await page.evaluate(() => navigator.userAgent);
|
|
332
|
+
const headers = {
|
|
356
333
|
'Accept': '*/*',
|
|
357
334
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
358
335
|
'Accept-Language': LanguageLocaleMap[this.language],
|
|
@@ -362,12 +339,18 @@ class MelCloud extends EventEmitter {
|
|
|
362
339
|
'Sec-Fetch-Dest': 'empty',
|
|
363
340
|
'Sec-Fetch-Mode': 'cors',
|
|
364
341
|
'Sec-Fetch-Site': 'same-origin',
|
|
342
|
+
'User-Agent': userAgent,
|
|
365
343
|
'x-csrf': '1'
|
|
366
344
|
};
|
|
345
|
+
this.headers = headers;
|
|
346
|
+
this.axiosInstance = axios.create({
|
|
347
|
+
baseURL: ApiUrlsHome.BaseURL,
|
|
348
|
+
timeout: 30000,
|
|
349
|
+
headers: headers
|
|
350
|
+
})
|
|
367
351
|
|
|
368
352
|
accountInfo.State = true;
|
|
369
353
|
accountInfo.Info = 'Connect to MELCloud Home Success';
|
|
370
|
-
accountInfo.Headers = this.headers;
|
|
371
354
|
await this.functions.saveData(this.accountFile, accountInfo);
|
|
372
355
|
|
|
373
356
|
return accountInfo;
|
|
@@ -385,13 +368,8 @@ class MelCloud extends EventEmitter {
|
|
|
385
368
|
|
|
386
369
|
async send(accountInfo) {
|
|
387
370
|
try {
|
|
388
|
-
await
|
|
389
|
-
|
|
390
|
-
baseURL: ApiUrlsHome.BaseURL,
|
|
391
|
-
timeout: 15000,
|
|
392
|
-
headers: accountInfo.Headers
|
|
393
|
-
});
|
|
394
|
-
await this.functions.saveData(this.accountFile, accountInfo);
|
|
371
|
+
//await this.axiosInstance(ApiUrlsHome.UpdateApplicationOptions, { method: 'POST' });
|
|
372
|
+
//await this.functions.saveData(this.accountFile, accountInfo);
|
|
395
373
|
return true;
|
|
396
374
|
} catch (error) {
|
|
397
375
|
throw new Error(`Send data error: ${error.message}`);
|