homebridge-melcloud-control 4.0.0-beta.286 → 4.0.0-beta.288
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 +25 -29
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.288",
|
|
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
|
@@ -312,42 +312,38 @@ class MelCloud extends EventEmitter {
|
|
|
312
312
|
|
|
313
313
|
// 2️⃣ Jeśli nie w URL, sprawdź body HTML (form_post)
|
|
314
314
|
const html = await page.content();
|
|
315
|
-
console.log(html);
|
|
316
315
|
|
|
317
|
-
//
|
|
318
|
-
const formCodeMatch =
|
|
319
|
-
const formStateMatch =
|
|
320
|
-
const formActionMatch =
|
|
316
|
+
// Check for form_post response (HTML with hidden form)
|
|
317
|
+
const formCodeMatch = data.match(/name="code"\s+value="([^"]+)"/);
|
|
318
|
+
const formStateMatch = data.match(/name="state"\s+value="([^"]+)"/);
|
|
319
|
+
const formActionMatch = data.match(/action="([^"]+)"/);
|
|
321
320
|
|
|
322
321
|
if (formCodeMatch && formStateMatch && formActionMatch) {
|
|
323
|
-
console.log('
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
formData.append('state', formStateMatch[1]);
|
|
329
|
-
|
|
330
|
-
const response = await page.evaluate(async (url, body) => {
|
|
331
|
-
const res = await fetch(url, {
|
|
332
|
-
method: 'POST',
|
|
333
|
-
body,
|
|
334
|
-
credentials: 'include'
|
|
335
|
-
});
|
|
336
|
-
return res.text();
|
|
337
|
-
}, actionUrl, formData);
|
|
338
|
-
|
|
339
|
-
// Spróbuj znaleźć code w odpowiedzi POST
|
|
340
|
-
const postCodeMatch = response.match(/code=([^&"']+)/);
|
|
341
|
-
if (postCodeMatch) return postCodeMatch[1];
|
|
322
|
+
console.log('Found form_post response, submitting to callback endpoint...');
|
|
323
|
+
this.submitFormPost(formActionMatch[1], formCodeMatch[1], formStateMatch[1], cookies)
|
|
324
|
+
.then(code => resolve(code))
|
|
325
|
+
.catch(err => reject(err));
|
|
326
|
+
return;
|
|
342
327
|
}
|
|
343
328
|
|
|
344
|
-
//
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
347
|
-
console.log('
|
|
348
|
-
|
|
329
|
+
// Check for melcloudhome:// redirect in JS
|
|
330
|
+
const bodyCodeMatch = data.match(/melcloudhome:\/\/[^"'\s]*[?&]code=([^&"'\s]+)/);
|
|
331
|
+
if (bodyCodeMatch) {
|
|
332
|
+
console.log('Found authorization code in response body (JS)');
|
|
333
|
+
resolve(bodyCodeMatch[1]);
|
|
334
|
+
return;
|
|
349
335
|
}
|
|
350
336
|
|
|
337
|
+
// 🆕 NEW: Check for data-url with code parameter (like in 500 error pages)
|
|
338
|
+
const dataUrlMatch = data.match(/data-url="[^"]*code=([^&"']+)/);
|
|
339
|
+
if (dataUrlMatch) {
|
|
340
|
+
console.log('Found authorization code in data-url attribute');
|
|
341
|
+
resolve(dataUrlMatch[1]);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
reject(new Error('Authorization code not found in URL or HTML'));
|
|
346
|
+
|
|
351
347
|
// 5. Wymień code na access_token
|
|
352
348
|
const tokenResponse = await axios.post(TOKEN_ENDPOINT, new URLSearchParams({
|
|
353
349
|
client_id: 'homemobile',
|