homebridge-melcloud-control 4.0.0-beta.290 → 4.0.0-beta.292

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.290",
4
+ "version": "4.0.0-beta.292",
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
@@ -281,17 +281,6 @@ class MelCloud extends EventEmitter {
281
281
  }
282
282
 
283
283
  async connectToMelCloudHome() {
284
- const mel = new MelCloudHomeToken(console);
285
- try {
286
- const tokens = await mel.loginWithCredentials(this.user, this.passwd);
287
- console.log('✅ Access Token:', tokens.access_token);
288
- console.log('🔁 Refresh Token:', tokens.refresh_token);
289
- } catch (err) {
290
- console.error('❌ Login failed:', err.message);
291
- }
292
- }
293
-
294
- async connectToMelCloudHome2() {
295
284
  let browser;
296
285
  try {
297
286
  browser = await puppeteer.launch({
@@ -300,7 +289,7 @@ class MelCloud extends EventEmitter {
300
289
  });
301
290
 
302
291
  const melCloudHomeToken = new MelCloudHomeToken();
303
- const url = await melCloudHomeToken.getUrl();
292
+ const url = await melCloudHomeToken.buildAuthorizeUrl();
304
293
 
305
294
  this.emit('warn', url);
306
295
 
@@ -322,7 +311,11 @@ class MelCloud extends EventEmitter {
322
311
  }
323
312
 
324
313
  // 2️⃣ Jeśli nie w URL, sprawdź body HTML (form_post)
325
- const html = await page.content();
314
+ const html = await page.content(html);
315
+ const code = await melCloudHomeToken.extractCodeFromHtml();
316
+
317
+ console.log(code);
318
+ return
326
319
 
327
320
  // Check for form_post response (HTML with hidden form)
328
321
  const formCodeMatch = html.match(/name="code"\s+value="([^"]+)"/);
@@ -75,65 +75,9 @@ class MelCloudHomeToken {
75
75
  return code;
76
76
  }
77
77
 
78
- async exchangeCodeForTokens(code) {
79
- const body = new URLSearchParams({
80
- client_id: CLIENT_ID,
81
- grant_type: 'authorization_code',
82
- redirect_uri: REDIRECT_URI,
83
- code_verifier: this.pkce.verifier,
84
- code,
85
- });
86
-
87
- const res = await this.client.post(TOKEN_ENDPOINT, body, {
88
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
89
- });
90
-
91
- return res.data;
92
- }
93
78
 
94
- /**
95
- * Main method: performs full login flow using email and password
96
- */
97
- async loginWithCredentials(email, password) {
98
- const authorizeUrl = await this.buildAuthorizeUrl();
99
- this.log.debug('Fetching login page...');
100
- const res = await this.client.get(authorizeUrl);
101
-
102
- const $ = cheerio.load(res.data);
103
- const form = $('form');
104
- const action = form.attr('action') || '/Account/Login';
105
- const requestVerificationToken = $('input[name="__RequestVerificationToken"]').val();
106
- const returnUrl = $('input[name="ReturnUrl"]').val() || '';
107
-
108
- this.log.debug('Submitting credentials...');
109
- const loginRes = await this.client.post(
110
- new URL(action, LOGIN_ENDPOINT).toString(),
111
- new URLSearchParams({
112
- Username: email,
113
- Password: password,
114
- __RequestVerificationToken: requestVerificationToken,
115
- ReturnUrl: returnUrl,
116
- }),
117
- {
118
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
119
- maxRedirects: 0,
120
- validateStatus: status => status < 400 || status === 302 || status === 500,
121
- }
122
- );
123
-
124
- let html = loginRes.data;
125
- if (typeof html !== 'string' && loginRes.headers.location) {
126
- const redirect = await this.client.get(loginRes.headers.location);
127
- html = redirect.data;
128
- }
129
79
 
130
- const code = await this.extractCodeFromHtml(html);
131
- if (!code) throw new Error('Authorization code not found in HTML');
132
80
 
133
- this.log.debug(`Found authorization code: ${code}`);
134
-
135
- return await this.exchangeCodeForTokens(code);
136
- }
137
81
  }
138
82
 
139
83
  export default MelCloudHomeToken;