homebridge-melcloud-control 4.0.0-beta.327 → 4.0.0-beta.329

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.327",
4
+ "version": "4.0.0-beta.329",
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
@@ -282,9 +282,7 @@ class MelCloud extends EventEmitter {
282
282
  }
283
283
 
284
284
  async connectToMelCloudHome() {
285
- let browser;
286
285
  try {
287
-
288
286
  const melCloudHomeToken = new MelCloudHomeToken({
289
287
  user: this.user,
290
288
  passwd: this.passwd,
@@ -303,7 +301,6 @@ class MelCloud extends EventEmitter {
303
301
 
304
302
  return accountInfo
305
303
  } catch (error) {
306
- if (browser) await browser.close().catch(() => { });
307
304
  throw error;
308
305
  }
309
306
  }
@@ -154,6 +154,31 @@ class MelCloudHomeToken extends EventEmitter {
154
154
  if (response.status === 302 && response.headers.location) {
155
155
  // Login success — mamy redirect z "code="
156
156
  const redirectUrl = response.headers.location;
157
+
158
+ // 🔹 wykonaj GET na redirect URL (tam ustawiane są C1/C2)
159
+ const finalResp = await axios.get(redirectUrl, {
160
+ headers: {
161
+ 'User-Agent': MOBILE_USER_AGENT,
162
+ },
163
+ maxRedirects: 0,
164
+ validateStatus: s => [200, 302].includes(s),
165
+ });
166
+
167
+ const finalCookies = finalResp.headers['set-cookie'] || [];
168
+ const c1 = finalCookies.find(c => c.startsWith('__Secure-monitorandcontrolC1='))?.split(';')[0];
169
+ const c2 = finalCookies.find(c => c.startsWith('__Secure-monitorandcontrolC2='))?.split(';')[0];
170
+
171
+ if (c1 && c2) {
172
+ const cookieHeader = [
173
+ '__Secure-monitorandcontrol=chunks-2',
174
+ c1,
175
+ c2
176
+ ].join('; ');
177
+ if (this.logWarn) this.emit('warn', `Cookie returned: ${cookieHeader}`);
178
+
179
+ return cookieHeader;
180
+ }
181
+
157
182
  const match = redirectUrl.match(/[?&]code=([^&]+)/);
158
183
  if (match) {
159
184
  const code = match[1];