homebridge-melcloud-control 4.0.0-beta.328 → 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.328",
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",
@@ -144,7 +144,7 @@ class MelCloudHomeToken extends EventEmitter {
144
144
  maxRedirects: 0,
145
145
  validateStatus: status => [200, 302, 400].includes(status),
146
146
  });
147
- if (this.logWarn) this.emit('warn', `Cookie returned from login: ${cookies}`);
147
+
148
148
  const cookie = response.headers['set-cookie'];
149
149
  if (cookie) {
150
150
  if (this.logWarn) this.emit('warn', `Cookie returned from login: ${cookie}`);
@@ -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];