homebridge-melcloud-control 4.9.0-beta.6 β†’ 4.9.0-beta.8

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/melcloudhome.js +15 -18
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.9.0-beta.6",
4
+ "version": "4.9.0-beta.8",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -408,30 +408,27 @@ class MelCloudHome extends EventEmitter {
408
408
  if (this.logDebug) this.emit('debug', 'Step 4: Follow Cognito β†’ IdentityServer redirect');
409
409
 
410
410
  const cognitoRedirectLocation = credResp.headers?.location ?? '';
411
-
412
- if (!cognitoRedirectLocation) {
413
- throw new Error('No Location header in Cognito response');
414
- }
411
+ if (!cognitoRedirectLocation) throw new Error('No Location header in Cognito response');
415
412
 
416
413
  if (this.logDebug) this.emit('debug', `Step 4 location: ${cognitoRedirectLocation}`);
417
414
 
418
- // πŸ”₯ NOWA LOGIKA
419
- if (cognitoRedirectLocation.includes('/signin-oidc-meu')) {
420
- if (this.logDebug) this.emit('debug', 'Detected direct code in signin-oidc-meu');
421
-
422
- const codeMatch = /code=([^&]+)/.exec(cognitoRedirectLocation);
423
- if (!codeMatch) throw new Error('No code in signin-oidc-meu redirect');
415
+ const signinUrl = cognitoRedirectLocation.startsWith('http')
416
+ ? cognitoRedirectLocation
417
+ : `https://${cognitoHostname}${cognitoRedirectLocation}`;
424
418
 
425
- const authCode = codeMatch[1];
426
-
427
- if (this.logDebug) this.emit('debug', `Got auth code directly: ${authCode.slice(0, 20)}...`);
419
+ // GET na signin-oidc-meu β€” IdentityServer przetworzy i przekieruje do melcloudhome://
420
+ const signinResp = await this.pace(() =>
421
+ client.post(signinUrl, {
422
+ headers: { 'User-Agent': ApiUrls.Home.UserAgent },
423
+ maxRedirects: 0, // przechwytujemy redirect do melcloudhome://
424
+ })
425
+ );
428
426
 
429
- const exchangeRes = await this.exchangeCodeForTokens(client, authCode, codeVerifier);
430
- return this._buildConnectInfo(connectInfo, exchangeRes);
427
+ if (this.logDebug) {
428
+ this.emit('debug', `Step 4 signin status: ${signinResp.status}`);
429
+ this.emit('debug', `Step 4 signin location: ${signinResp.headers?.location ?? '(none)'}`);
431
430
  }
432
431
 
433
-
434
-
435
432
  // ── Step 5: WyciΔ…gnij auth code z redirectu melcloudhome:// ───────────
436
433
  if (this.logDebug) this.emit('debug', 'Step 5: Extract auth code from redirect');
437
434
 
@@ -461,7 +458,7 @@ class MelCloudHome extends EventEmitter {
461
458
 
462
459
  if (this.logDebug) this.emit('debug', `Got auth code: ${authCode.slice(0, 20)}...`);
463
460
 
464
- // ── Step 6: WymieΕ„ kod na tokeny (WAΕ»NE: await!) ──────────────────
461
+ // ── Step 6: WymieΕ„ kod na tokeny ──────────────────
465
462
  const exchangeRes = await this.exchangeCodeForTokens(client, authCode, codeVerifier);
466
463
  return this._buildConnectInfo(connectInfo, exchangeRes);
467
464