homebridge-melcloud-control 4.0.0-beta.331 → 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.331",
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,6 +132,8 @@ 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}`);
136
+
135
137
  // Step 3: Wyślij POST z danymi logowania
136
138
  const response = await axios.post(url, form.toString(), {
137
139
  headers: {
@@ -150,34 +152,12 @@ class MelCloudHomeToken extends EventEmitter {
150
152
  const redirectUrl = response.headers.location;
151
153
  if (this.logWarn) this.emit('warn', `Redirect URL: ${redirectUrl}`);
152
154
 
153
- // 🔹 wykonaj GET na redirect URL (tam ustawiane są C1/C2)
154
- const finalResp = await axios.get(redirectUrl, {
155
- headers: {
156
- 'User-Agent': MOBILE_USER_AGENT,
157
- },
158
- maxRedirects: 0,
159
- validateStatus: s => [200, 302].includes(s),
160
- });
161
-
162
- if (this.logWarn) this.emit('warn', `Redirect URL: ${finalResp}`);
163
-
164
- const finalCookies = finalResp.headers['set-cookie'] || [];
165
- const c1 = finalCookies.find(c => c.startsWith('__Secure-monitorandcontrolC1='))?.split(';')[0];
166
- const c2 = finalCookies.find(c => c.startsWith('__Secure-monitorandcontrolC2='))?.split(';')[0];
167
-
168
- if (c1 && c2) {
169
- const cookieHeader = ['__Secure-monitorandcontrol=chunks-2', c1, c2].join('; ');
170
- if (this.logWarn) this.emit('warn', `Cookie returned: ${cookieHeader}`);
171
-
172
- return cookieHeader;
173
- }
174
-
175
155
  const match = redirectUrl.match(/[?&]code=([^&]+)/);
176
156
  if (match) {
177
157
  const code = match[1];
158
+ if (this.logWarn) this.emit('warn', `Redirect URL found code: ${code}`);
178
159
  return code;
179
160
  } else {
180
- console.warn('Redirect URL found, but no "code=" param.');
181
161
  if (this.logWarn) this.emit('warn', `Redirect URL found, but no "code=" param: ${redirectUrl}`);
182
162
  return null;
183
163
  }