homebridge-melcloud-control 4.0.0-beta.479 → 4.0.0-beta.480

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/melcloud.js +15 -8
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.479",
4
+ "version": "4.0.0-beta.480",
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
@@ -303,6 +303,7 @@ class MelCloud extends EventEmitter {
303
303
  return 'No chromium installed';
304
304
  }
305
305
 
306
+ this.emit('warn', `Test 1`);
306
307
  browser = await puppeteer.launch({
307
308
  headless: true,
308
309
  executablePath: chromiumPath,
@@ -320,9 +321,11 @@ class MelCloud extends EventEmitter {
320
321
  await new Promise(r => setTimeout(r, 1000));
321
322
 
322
323
  // Defensive check for main frame availability
324
+ this.emit('warn', `Test 2`);
323
325
  const pages = await browser.pages();
324
326
  let page = pages[0];
325
327
  if (!page) {
328
+ this.emit('warn', `Test 13`);
326
329
  if (this.logDebug) this.emit('debug', 'No initial page found, creating a new one.');
327
330
  page = await browser.newPage();
328
331
  }
@@ -330,6 +333,7 @@ class MelCloud extends EventEmitter {
330
333
  // Ensure page is ready
331
334
  await new Promise(r => setTimeout(r, 250));
332
335
 
336
+ this.emit('warn', `Test 3`);
333
337
  page.on('error', err => { if (this.logError) this.emit('error', `Page crashed: ${err.message}`); });
334
338
  page.on('pageerror', err => { if (this.logDebug) this.emit('error', `Browser error: ${err.message}`); });
335
339
  page.on('close', () => { if (this.logDebug) this.emit('debug', 'Page was closed unexpectedly'); });
@@ -339,12 +343,14 @@ class MelCloud extends EventEmitter {
339
343
  page.setDefaultNavigationTimeout(30000);
340
344
 
341
345
  // Now safe to navigate
346
+ this.emit('warn', `Test 4`);
342
347
  await page.goto(ApiUrlsHome.BaseURL, { waitUntil: ['domcontentloaded', 'networkidle2'] });
343
348
 
344
349
  let loginBtn;
345
350
  try {
346
351
  loginBtn = await page.waitForFunction(() => {
347
352
  const btns = Array.from(document.querySelectorAll('button.btn--blue'));
353
+ this.emit('warn', `Test 5`);
348
354
  return btns.find(b => ['Zaloguj', 'Sign In', 'Login'].includes(b.textContent.trim()));
349
355
  }, { timeout: 25000 }); // max 25s czekania
350
356
  } catch {
@@ -352,14 +358,13 @@ class MelCloud extends EventEmitter {
352
358
  return null;
353
359
  }
354
360
 
361
+ this.emit('warn', `Test 6`);
355
362
  await Promise.race([
356
- Promise.all([
357
- loginBtn.click(),
358
- page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 15000 })
359
- ]),
363
+ Promise.all([loginBtn.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 15000 })]),
360
364
  new Promise(r => setTimeout(r, 12000))
361
365
  ]);
362
366
 
367
+ this.emit('warn', `Test 7`);
363
368
  const usernameInput = await page.$('input[name="username"]');
364
369
  const passwordInput = await page.$('input[name="password"]');
365
370
  if (!usernameInput || !passwordInput) {
@@ -367,9 +372,11 @@ class MelCloud extends EventEmitter {
367
372
  return null;
368
373
  }
369
374
 
375
+ this.emit('warn', `Test 8`);
370
376
  await page.type('input[name="username"]', this.user, { delay: 50 });
371
377
  await page.type('input[name="password"]', this.passwd, { delay: 50 });
372
378
 
379
+ this.emit('warn', `Test 9`);
373
380
  const submitButton = await page.$('input[type="submit"], button[type="submit"]');
374
381
  if (!submitButton) {
375
382
  if (this.logWarn) this.emit('warn', 'Submit button not found on login form');
@@ -377,13 +384,11 @@ class MelCloud extends EventEmitter {
377
384
  }
378
385
 
379
386
  await Promise.race([
380
- Promise.all([
381
- submitButton.click(),
382
- page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 20000 })
383
- ]),
387
+ Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 20000 })]),
384
388
  new Promise(r => setTimeout(r, 15000))
385
389
  ]);
386
390
 
391
+ this.emit('warn', `Test 10`);
387
392
  let c1 = null, c2 = null;
388
393
  const start = Date.now();
389
394
  while ((!c1 || !c2) && Date.now() - start < 20000) {
@@ -393,6 +398,7 @@ class MelCloud extends EventEmitter {
393
398
  if (!c1 || !c2) await new Promise(r => setTimeout(r, 500));
394
399
  }
395
400
 
401
+ this.emit('warn', `Test 11`);
396
402
  if (!c1 || !c2) {
397
403
  if (this.logWarn) this.emit('warn', 'Cookies C1/C2 missing after login');
398
404
  return null;
@@ -407,6 +413,7 @@ class MelCloud extends EventEmitter {
407
413
  const accountInfo = { ContextKey: contextKey, UseFahrenheit: false };
408
414
  this.contextKey = contextKey;
409
415
 
416
+ this.emit('warn', `Test 12`);
410
417
  await this.functions.saveData(this.accountFile, accountInfo);
411
418
 
412
419
  if (!refresh) this.emit('success', 'Connect to MELCloud Home Success');