homebridge-melcloud-control 4.0.0-beta.276 → 4.0.0-beta.278

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 +11 -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.276",
4
+ "version": "4.0.0-beta.278",
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
@@ -299,19 +299,23 @@ class MelCloud extends EventEmitter {
299
299
  await page.waitForSelector('input[name="username"]', { timeout: 5000 });
300
300
  await page.type('input[name="username"]', this.user, { delay: 50 });
301
301
  await page.type('input[name="password"]', this.passwd, { delay: 50 });
302
-
303
302
  const button1 = await page.$('input[type="Submit"]');
304
303
  await Promise.all([button1.click(), page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 10000 })]);
305
304
 
306
- // 4. Czekamy na przekierowanie z 'code' w URL
307
- //await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 20000 });
305
+ await new Promise(resolve => setTimeout(resolve, 1000));
306
+ // pobierz aktualny URL Puppeteera
308
307
  const currentUrl = page.url();
309
- console.log('Authorization code:', currentUrl);
310
- if (currentUrl.includes('code=')) {
311
- const code = new URL(currentUrl).searchParams.get('code');
312
- console.log('Authorization code:', code);
308
+
309
+ // wyciągnij parametr 'code'
310
+ const urlObj = new URL(currentUrl);
311
+ const code = urlObj.searchParams.get('code');
312
+
313
+ if (!code) {
314
+ throw new Error('Authorization code not found in URL');
313
315
  }
314
316
 
317
+ console.log('Authorization code:', code); console.log('Authorization code:', code);
318
+
315
319
  // 5. Wymień code na access_token
316
320
  const tokenResponse = await axios.post(TOKEN_ENDPOINT, new URLSearchParams({
317
321
  client_id: clientId,