homebridge-melcloud-control 4.0.0-beta.534 → 4.0.0-beta.535
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 +18 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.535",
|
|
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
|
@@ -344,7 +344,8 @@ class MelCloud extends EventEmitter {
|
|
|
344
344
|
]
|
|
345
345
|
});
|
|
346
346
|
|
|
347
|
-
const
|
|
347
|
+
const context = await browser.createIncognitoBrowserContext();
|
|
348
|
+
const page = await context.newPage();
|
|
348
349
|
page.setDefaultTimeout(GLOBAL_TIMEOUT);
|
|
349
350
|
page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
|
|
350
351
|
|
|
@@ -365,20 +366,18 @@ class MelCloud extends EventEmitter {
|
|
|
365
366
|
await new Promise(r => setTimeout(r, 3000));
|
|
366
367
|
|
|
367
368
|
this.emit('warn', `Looking for login button...`);
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
const btns = Array.from(document.querySelectorAll('button.btn--blue'));
|
|
372
|
-
return btns.find(b => ['Zaloguj', 'Sign In', 'Login'].includes(b.textContent.trim()));
|
|
373
|
-
}, { timeout: GLOBAL_TIMEOUT / 6 });
|
|
374
|
-
} catch {
|
|
369
|
+
const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT / 6 });
|
|
370
|
+
const loginText = await loginBtn.evaluate(el => el.textContent.trim());
|
|
371
|
+
if (!['Zaloguj', 'Sign In', 'Login'].includes(loginText)) {
|
|
375
372
|
accountInfo.State = false;
|
|
376
|
-
accountInfo.Info = 'Login button not found';
|
|
373
|
+
accountInfo.Info = 'Login button not found or has unexpected label';
|
|
377
374
|
return accountInfo;
|
|
378
375
|
}
|
|
379
376
|
|
|
380
377
|
this.emit('warn', `Found login button ${loginBtn}`);
|
|
381
|
-
await
|
|
378
|
+
await loginBtn.click();
|
|
379
|
+
await page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 4 });
|
|
380
|
+
|
|
382
381
|
|
|
383
382
|
this.emit('warn', `Looking for credentials form...`);
|
|
384
383
|
const usernameInput = await page.$('input[name="username"]');
|
|
@@ -439,8 +438,15 @@ class MelCloud extends EventEmitter {
|
|
|
439
438
|
throw new Error(`Connect error: ${error.message}`);
|
|
440
439
|
} finally {
|
|
441
440
|
if (browser) {
|
|
442
|
-
try {
|
|
443
|
-
|
|
441
|
+
try {
|
|
442
|
+
const contexts = browser.browserContexts();
|
|
443
|
+
for (const ctx of contexts) {
|
|
444
|
+
await ctx.close().catch(() => { });
|
|
445
|
+
}
|
|
446
|
+
await browser.close();
|
|
447
|
+
} catch (closeErr) {
|
|
448
|
+
this.emit('error', `Failed to close Puppeteer: ${closeErr.message}`);
|
|
449
|
+
}
|
|
444
450
|
}
|
|
445
451
|
}
|
|
446
452
|
}
|