homebridge-melcloud-control 4.3.11-beta.21 → 4.3.11-beta.23

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.3.11-beta.21",
4
+ "version": "4.3.11-beta.23",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -40,10 +40,7 @@
40
40
  "axios": "^1.13.2",
41
41
  "express": "^5.2.1",
42
42
  "puppeteer": "^24.32.0",
43
- "ws": "^8.18.3",
44
- "axios-cookiejar-support": "^6.0.5",
45
- "tough-cookie": "^6.0.0",
46
- "jsdom": "^27.2.0"
43
+ "ws": "^8.18.3"
47
44
  },
48
45
  "keywords": [
49
46
  "homebridge",
@@ -268,7 +268,7 @@ class MelCloudHome extends EventEmitter {
268
268
  }
269
269
  }
270
270
 
271
- async connect1() {
271
+ async connect() {
272
272
  if (this.logDebug) this.emit('debug', 'Connecting to MELCloud Home');
273
273
  const GLOBAL_TIMEOUT = 90000;
274
274
 
@@ -454,22 +454,6 @@ class MelCloudHome extends EventEmitter {
454
454
  }
455
455
  }
456
456
  }
457
-
458
- async connect() {
459
- if (this.logDebug) this.emit('debug', 'Connecting to MELCloud Home');
460
- const auth = new MELCloudHomeAuth();
461
- try {
462
- await auth.login(this.user, this.passwd);
463
- console.log('Logged in!');
464
-
465
- const valid = await auth.checkSession();
466
- console.log('Session valid:', valid);
467
-
468
- console.log('Cookies:', auth.getCookies());
469
- } catch (err) {
470
- console.error(err.message);
471
- }
472
- }
473
457
  }
474
458
 
475
459
  export default MelCloudHome;
@@ -1,112 +0,0 @@
1
- import axios from 'axios';
2
- import { CookieJar } from 'tough-cookie';
3
- import { wrapper } from 'axios-cookiejar-support';
4
- import { JSDOM } from 'jsdom';
5
- import qs from 'qs';
6
-
7
- const BASE_URL = 'https://melcloudhome.com'; // lub właściwe dla Home
8
- const USER_AGENT =
9
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36';
10
-
11
- export class MELCloudHomeAuth {
12
- constructor() {
13
- this.jar = new CookieJar();
14
- this.client = wrapper(
15
- axios.create({
16
- jar: this.jar,
17
- withCredentials: true,
18
- headers: {
19
- 'User-Agent': USER_AGENT,
20
- Accept:
21
- 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
22
- 'Accept-Language': 'en-US,en;q=0.9',
23
- },
24
- maxRedirects: 0,
25
- validateStatus: (status) => status >= 200 && status < 400,
26
- })
27
- );
28
- this.authenticated = false;
29
- }
30
-
31
- async login(username, password) {
32
- try {
33
- // 1. GET login page to get CSRF token
34
- let resp = await this.client.get(`${BASE_URL}/bff/login`, {
35
- params: { returnUrl: '/dashboard' },
36
- });
37
-
38
- // Follow redirect to Cognito
39
- let finalUrl = resp.request.res.responseUrl;
40
- if (!finalUrl.includes('.amazoncognito.com')) {
41
- throw new Error('Unexpected redirect URL: ' + finalUrl);
42
- }
43
-
44
- // Extract CSRF token from HTML
45
- const csrfToken = this.extractCsrfToken(resp.data);
46
- if (!csrfToken) throw new Error('CSRF token not found');
47
-
48
- // 2. POST credentials to Cognito
49
- const loginData = qs.stringify({
50
- _csrf: csrfToken,
51
- username,
52
- password,
53
- cognitoAsfData: '', // minimal value, może być potrzebne pełne ASF
54
- });
55
-
56
- resp = await this.client.post(finalUrl, loginData, {
57
- headers: {
58
- 'Content-Type': 'application/x-www-form-urlencoded',
59
- Origin: 'https://live-melcloudhome.auth.eu-west-1.amazoncognito.com',
60
- Referer: finalUrl,
61
- },
62
- maxRedirects: 5,
63
- });
64
-
65
- finalUrl = resp.request.res.responseUrl;
66
-
67
- // Sprawdzenie czy udało się zalogować
68
- if (
69
- finalUrl.includes('melcloudhome.com/dashboard') &&
70
- resp.status < 400
71
- ) {
72
- console.log('Authentication successful');
73
- this.authenticated = true;
74
- return true;
75
- }
76
-
77
- throw new Error('Authentication failed, final URL: ' + finalUrl);
78
- } catch (err) {
79
- throw new Error('Login error: ' + err.message);
80
- }
81
- }
82
-
83
- extractCsrfToken(html) {
84
- const dom = new JSDOM(html);
85
- const input = dom.window.document.querySelector('input[name="_csrf"]');
86
- return input?.value || null;
87
- }
88
-
89
- async checkSession() {
90
- if (!this.authenticated) return false;
91
-
92
- try {
93
- const resp = await this.client.get(`${BASE_URL}/api/user/context`, {
94
- headers: { 'x-csrf': '1', Referer: `${BASE_URL}/dashboard` },
95
- });
96
- return resp.status === 200;
97
- } catch {
98
- this.authenticated = false;
99
- return false;
100
- }
101
- }
102
-
103
- getCookies() {
104
- return this.jar.toJSON();
105
- }
106
- }
107
-
108
-
109
-
110
- export default MELCloudHomeAuth;
111
-
112
-