homebridge-melcloud-control 4.0.0-beta.25 → 4.0.0-beta.27
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/melcloud.js +27 -6
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.27",
|
|
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
|
@@ -273,22 +273,43 @@ class MelCloud extends EventEmitter {
|
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
// Kliknij i czekaj na zmianę adresu
|
|
276
|
-
const [
|
|
276
|
+
const [resp] = await Promise.all([
|
|
277
277
|
page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: 20000 }),
|
|
278
278
|
loginBtn.click(),
|
|
279
279
|
]);
|
|
280
280
|
|
|
281
281
|
// Wypisz adres po przekierowaniu
|
|
282
282
|
const currentUrl = page.url();
|
|
283
|
-
this.emit('warn', JSON.stringify(currentUrl, null, 2));
|
|
284
283
|
|
|
284
|
+
// Zamknij przeglądarkę
|
|
285
|
+
await browser.close();
|
|
285
286
|
|
|
286
|
-
//
|
|
287
|
-
|
|
287
|
+
// Utwórz dane logowania
|
|
288
|
+
const form = new URLSearchParams();
|
|
289
|
+
form.append('input[username]', this.user);
|
|
290
|
+
form.append('input[password]', this.passwd);
|
|
288
291
|
|
|
289
|
-
|
|
290
|
-
|
|
292
|
+
// Wyślij POST za pomocą axios
|
|
293
|
+
this.emit('warn', 'Sending login request via axios...');
|
|
294
|
+
const response = await axios.post(currentUrl, {
|
|
295
|
+
data: form,
|
|
296
|
+
timeout: 10000
|
|
297
|
+
});
|
|
298
|
+
this.emit('warn', `Login response: ${JSON.stringify(response)}`);
|
|
291
299
|
|
|
300
|
+
this.emit('warn', `Login request status: ${response}`);
|
|
301
|
+
if (response.status !== 200) {
|
|
302
|
+
this.emit('error', `Login failed with status code: ${response.status}`);
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const cookie = response.headers['set-cookie'];
|
|
307
|
+
if (!cookie) {
|
|
308
|
+
this.emit('warn', `No cookie returned from login. Response headers: ${JSON.stringify(response.headers)}`);
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return cookie;
|
|
292
313
|
} catch (err) {
|
|
293
314
|
this.emit('error', `Login failed: ${err.message}`);
|
|
294
315
|
return null;
|