homebridge-melcloud-control 4.0.0-beta.7 → 4.0.0-beta.9
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 +28 -7
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.9",
|
|
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
|
@@ -262,20 +262,41 @@ class MelCloud extends EventEmitter {
|
|
|
262
262
|
throw new Error('❌ Could not find login button on the page.');
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
await page
|
|
265
|
+
// Opcjonalnie obsługa "Stay signed in?"
|
|
266
|
+
const staySignedInSelector = 'input[name="rememberDevice"], button[type="submit"]';
|
|
267
|
+
if (await page.$(staySignedInSelector)) {
|
|
268
|
+
console.log('Handling "Stay signed in?" screen...');
|
|
269
|
+
await Promise.all([
|
|
270
|
+
page.click(staySignedInSelector),
|
|
271
|
+
page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 20000 })
|
|
272
|
+
]);
|
|
273
|
+
}
|
|
268
274
|
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
275
|
+
// Monitorowanie requestów i oczekiwanie na cookies C1 i C2
|
|
276
|
+
let c1 = null, c2 = null;
|
|
277
|
+
page.on('response', async response => {
|
|
278
|
+
const url = response.url();
|
|
279
|
+
if (url.includes('GetDevices') || url.includes('Dashboard')) {
|
|
280
|
+
const cookies = await page.cookies();
|
|
281
|
+
c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || c1;
|
|
282
|
+
c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || c2;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// Retry loop max 15s
|
|
287
|
+
const start = Date.now();
|
|
288
|
+
while ((!c1 || !c2) && Date.now() - start < 15000) {
|
|
289
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (!c1 || !c2) throw new Error('Cookies C1/C2 not found after login');
|
|
273
293
|
|
|
274
294
|
const data = { C1: c1, C2: c2, date: new Date().toISOString() };
|
|
275
295
|
await this.functions.saveData(this.cookiesFile, data);
|
|
276
296
|
|
|
277
297
|
this.emit('warn', 'Login successful.');
|
|
278
298
|
return data;
|
|
299
|
+
|
|
279
300
|
} catch (err) {
|
|
280
301
|
this.emit('error', `Login failed: ${err.message}`);
|
|
281
302
|
return null;
|