homebridge-melcloud-control 4.0.0-beta.332 → 4.0.0-beta.333

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.332",
4
+ "version": "4.0.0-beta.333",
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
@@ -294,9 +294,13 @@ class MelCloud extends EventEmitter {
294
294
  .on('error', error => this.emit('error', error));
295
295
 
296
296
  const data = await melCloudHomeToken.buildAuthorizeUrl();
297
- const cookies = await melCloudHomeToken.loginToMelCloudHome(data.url);
298
297
 
299
- const accountInfo = { ContextKey: cookies, UseFahrenheit: false };
298
+ const url = data.url;
299
+ const codeVerifier = data.codeVerifier;
300
+ const code = await melCloudHomeToken.loginToMelCloudHome(url);
301
+ const token = await melCloudHomeToken.getTokens(code, codeVerifier);
302
+
303
+ const accountInfo = { ContextKey: token, UseFahrenheit: false };
300
304
  this.contextKey = cookies;
301
305
 
302
306
  return accountInfo
@@ -132,7 +132,7 @@ class MelCloudHomeToken extends EventEmitter {
132
132
  form.append('cognitoAsfData', '');
133
133
  form.append('_csrf', csrf);
134
134
 
135
- if (this.logWarn) this.emit('warn', `Redirect URL: ${url}`);
135
+ if (this.logWarn) this.emit('warn', `Redirect URL: ${url}`);
136
136
 
137
137
  // Step 3: Wyślij POST z danymi logowania
138
138
  const response = await axios.post(url, form.toString(), {
@@ -152,34 +152,12 @@ class MelCloudHomeToken extends EventEmitter {
152
152
  const redirectUrl = response.headers.location;
153
153
  if (this.logWarn) this.emit('warn', `Redirect URL: ${redirectUrl}`);
154
154
 
155
- // 🔹 wykonaj GET na redirect URL (tam ustawiane są C1/C2)
156
- const finalResp = await axios.get(redirectUrl, {
157
- headers: {
158
- 'User-Agent': MOBILE_USER_AGENT,
159
- },
160
- maxRedirects: 0,
161
- validateStatus: s => [200, 302].includes(s),
162
- });
163
-
164
- if (this.logWarn) this.emit('warn', `Redirect URL: ${finalResp}`);
165
-
166
- const finalCookies = finalResp.headers['set-cookie'] || [];
167
- const c1 = finalCookies.find(c => c.startsWith('__Secure-monitorandcontrolC1='))?.split(';')[0];
168
- const c2 = finalCookies.find(c => c.startsWith('__Secure-monitorandcontrolC2='))?.split(';')[0];
169
-
170
- if (c1 && c2) {
171
- const cookieHeader = ['__Secure-monitorandcontrol=chunks-2', c1, c2].join('; ');
172
- if (this.logWarn) this.emit('warn', `Cookie returned: ${cookieHeader}`);
173
-
174
- return cookieHeader;
175
- }
176
-
177
155
  const match = redirectUrl.match(/[?&]code=([^&]+)/);
178
156
  if (match) {
179
157
  const code = match[1];
158
+ if (this.logWarn) this.emit('warn', `Redirect URL found code: ${code}`);
180
159
  return code;
181
160
  } else {
182
- console.warn('Redirect URL found, but no "code=" param.');
183
161
  if (this.logWarn) this.emit('warn', `Redirect URL found, but no "code=" param: ${redirectUrl}`);
184
162
  return null;
185
163
  }