homebridge-melcloud-control 4.2.5-beta.8 → 4.2.5
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/CHANGELOG.md +12 -0
- package/README.md +19 -18
- package/config.schema.json +11 -11
- package/index.js +6 -15
- package/package.json +2 -2
- package/src/constants.js +1 -0
- package/src/deviceata.js +33 -30
- package/src/deviceatw.js +31 -28
- package/src/deviceerv.js +31 -28
- package/src/melcloud.js +3 -14
- package/src/melcloudata.js +70 -52
- package/src/melcloudatw.js +65 -45
- package/src/melclouderv.js +77 -57
- package/src/melcloudhome.js +18 -33
package/src/melcloudhome.js
CHANGED
|
@@ -9,7 +9,7 @@ import Functions from './functions.js';
|
|
|
9
9
|
import { ApiUrlsHome, LanguageLocaleMap } from './constants.js';
|
|
10
10
|
const execPromise = promisify(exec);
|
|
11
11
|
|
|
12
|
-
class
|
|
12
|
+
class MelCloudHome extends EventEmitter {
|
|
13
13
|
constructor(account, accountFile, buildingsFile, devicesFile, pluginStart = false) {
|
|
14
14
|
super();
|
|
15
15
|
this.accountType = account.type;
|
|
@@ -61,7 +61,6 @@ 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`);
|
|
@@ -195,10 +194,17 @@ class MelCloud extends EventEmitter {
|
|
|
195
194
|
return devicesList;
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
|
|
197
|
+
// Get scenes
|
|
198
|
+
let scenes = [];
|
|
199
|
+
try {
|
|
200
|
+
scenes = await this.checkScenesList();
|
|
201
|
+
if (this.logDebug) this.emit('debug', `Found ${scenes.length} svenes`);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (this.logDebug) this.emit('debug', `Get scenes error: ${error} `);
|
|
204
|
+
}
|
|
199
205
|
|
|
200
206
|
devicesList.State = true;
|
|
201
|
-
devicesList.Info = `Found ${devicesCount} devices`;
|
|
207
|
+
devicesList.Info = `Found ${devicesCount} devices and ${scenes.length} scenes`;
|
|
202
208
|
devicesList.Devices = devices;
|
|
203
209
|
devicesList.Scenes = scenes;
|
|
204
210
|
devicesList.Headers = this.headers;
|
|
@@ -208,12 +214,6 @@ class MelCloud extends EventEmitter {
|
|
|
208
214
|
|
|
209
215
|
return devicesList;
|
|
210
216
|
} catch (error) {
|
|
211
|
-
if (error.response?.status === 401) {
|
|
212
|
-
if (this.logWarn) this.emit('warn', 'Check devices list not possible, cookies expired, trying to get new.');
|
|
213
|
-
await this.connect();
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
217
|
throw new Error(`Check devices list error: ${error.message}`);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
@@ -224,7 +224,7 @@ class MelCloud extends EventEmitter {
|
|
|
224
224
|
|
|
225
225
|
let browser;
|
|
226
226
|
try {
|
|
227
|
-
const accountInfo = { State: false, Info: '',
|
|
227
|
+
const accountInfo = { State: false, Info: '', Account: {}, UseFahrenheit: false };
|
|
228
228
|
let chromiumPath = await this.functions.ensureChromiumInstalled();
|
|
229
229
|
|
|
230
230
|
// === Fallback to Puppeteer's built-in Chromium ===
|
|
@@ -276,14 +276,6 @@ class MelCloud extends EventEmitter {
|
|
|
276
276
|
page.setDefaultTimeout(GLOBAL_TIMEOUT);
|
|
277
277
|
page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
|
|
278
278
|
|
|
279
|
-
// Clear cookies before navigation
|
|
280
|
-
try {
|
|
281
|
-
const client = await page.createCDPSession();
|
|
282
|
-
await client.send('Network.clearBrowserCookies');
|
|
283
|
-
} catch (error) {
|
|
284
|
-
if (this.logError) this.emit('error', `Clear cookies error: ${error.message}`);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
279
|
try {
|
|
288
280
|
await page.goto(ApiUrlsHome.BaseURL, { waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT });
|
|
289
281
|
} catch (error) {
|
|
@@ -293,7 +285,7 @@ class MelCloud extends EventEmitter {
|
|
|
293
285
|
|
|
294
286
|
// Wait extra to ensure UI is rendered
|
|
295
287
|
await new Promise(r => setTimeout(r, 3000));
|
|
296
|
-
const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT /
|
|
288
|
+
const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT / 3 });
|
|
297
289
|
const loginText = await page.evaluate(el => el.textContent.trim(), loginBtn);
|
|
298
290
|
|
|
299
291
|
if (!['Zaloguj', 'Sign In', 'Login'].includes(loginText)) {
|
|
@@ -319,13 +311,13 @@ class MelCloud extends EventEmitter {
|
|
|
319
311
|
accountInfo.Info = 'Submit button not found';
|
|
320
312
|
return accountInfo;
|
|
321
313
|
}
|
|
322
|
-
await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT /
|
|
314
|
+
await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 3 })]), new Promise(r => setTimeout(r, GLOBAL_TIMEOUT / 3))]);
|
|
323
315
|
|
|
324
316
|
// Extract cookies
|
|
325
317
|
let c1 = null, c2 = null;
|
|
326
318
|
const start = Date.now();
|
|
327
319
|
while ((!c1 || !c2) && Date.now() - start < GLOBAL_TIMEOUT / 2) {
|
|
328
|
-
const cookies = await
|
|
320
|
+
const cookies = await browser.cookies();
|
|
329
321
|
c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || c1;
|
|
330
322
|
c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || c2;
|
|
331
323
|
if (!c1 || !c2) await new Promise(r => setTimeout(r, 500));
|
|
@@ -342,6 +334,8 @@ class MelCloud extends EventEmitter {
|
|
|
342
334
|
`__Secure-monitorandcontrolC2=${c2}`
|
|
343
335
|
].join('; ');
|
|
344
336
|
|
|
337
|
+
|
|
338
|
+
const userAgent = await page.evaluate(() => navigator.userAgent);
|
|
345
339
|
const headers = {
|
|
346
340
|
'Accept': '*/*',
|
|
347
341
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
@@ -352,6 +346,7 @@ class MelCloud extends EventEmitter {
|
|
|
352
346
|
'Sec-Fetch-Dest': 'empty',
|
|
353
347
|
'Sec-Fetch-Mode': 'cors',
|
|
354
348
|
'Sec-Fetch-Site': 'same-origin',
|
|
349
|
+
'User-Agent': userAgent,
|
|
355
350
|
'x-csrf': '1'
|
|
356
351
|
};
|
|
357
352
|
this.headers = headers;
|
|
@@ -377,17 +372,7 @@ class MelCloud extends EventEmitter {
|
|
|
377
372
|
}
|
|
378
373
|
}
|
|
379
374
|
}
|
|
380
|
-
|
|
381
|
-
async send(accountInfo) {
|
|
382
|
-
try {
|
|
383
|
-
//await this.axiosInstance(ApiUrlsHome.UpdateApplicationOptions, { method: 'POST' });
|
|
384
|
-
//await this.functions.saveData(this.accountFile, accountInfo);
|
|
385
|
-
return true;
|
|
386
|
-
} catch (error) {
|
|
387
|
-
throw new Error(`Send data error: ${error.message}`);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
375
|
}
|
|
391
376
|
|
|
392
|
-
export default
|
|
377
|
+
export default MelCloudHome;
|
|
393
378
|
|