homebridge-melcloud-control 4.0.0-beta.315 → 4.0.0-beta.317
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 +1 -1
- package/src/melcloudhometoken.js +20 -5
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.
|
|
4
|
+
"version": "4.0.0-beta.317",
|
|
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/melcloudhometoken.js
CHANGED
|
@@ -163,7 +163,7 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
163
163
|
form.append('_csrf', csrf);
|
|
164
164
|
|
|
165
165
|
// Step 3: Wyślij POST z danymi logowania
|
|
166
|
-
const
|
|
166
|
+
const response = await axios.post(url, form.toString(), {
|
|
167
167
|
headers: {
|
|
168
168
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
169
169
|
'Cookie': cookies.join('; '),
|
|
@@ -175,16 +175,31 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
175
175
|
validateStatus: status => [200, 302, 400].includes(status),
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
-
this.emit('warn', `No cookie returned from login. Response headers: ${
|
|
178
|
+
this.emit('warn', `No cookie returned from login. Response headers: ${response}`);
|
|
179
|
+
if (response.status === 302 && postResp.headers.location) {
|
|
180
|
+
// Login success — mamy redirect z "code="
|
|
181
|
+
const redirectUrl = response.headers.location;
|
|
182
|
+
console.log('Login success, redirect URL:', redirectUrl);
|
|
183
|
+
|
|
184
|
+
const match = redirectUrl.match(/[?&]code=([^&]+)/);
|
|
185
|
+
if (match) {
|
|
186
|
+
const code = match[1];
|
|
187
|
+
console.log('Authorization code:', code);
|
|
188
|
+
return code;
|
|
189
|
+
} else {
|
|
190
|
+
console.warn('Redirect URL found, but no "code=" param.');
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
179
194
|
|
|
180
|
-
if (
|
|
181
|
-
if (this.logError) this.emit('error', `Login failed with status code: ${
|
|
195
|
+
if (response.status !== 200) {
|
|
196
|
+
if (this.logError) this.emit('error', `Login failed with status code: ${response.status}`);
|
|
182
197
|
return null;
|
|
183
198
|
}
|
|
184
199
|
|
|
185
200
|
const cookie = response.headers['set-cookie'];
|
|
186
201
|
if (!cookie) {
|
|
187
|
-
if (this.logWarn) this.emit('warn', `No cookie returned from login. Response headers: ${JSON.stringify(
|
|
202
|
+
if (this.logWarn) this.emit('warn', `No cookie returned from login. Response headers: ${JSON.stringify(response.headers)}`);
|
|
188
203
|
return null;
|
|
189
204
|
}
|
|
190
205
|
|