homebridge-melcloud-control 4.0.0-beta.263 → 4.0.0-beta.266
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 -40
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.266",
|
|
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
|
@@ -283,15 +283,14 @@ class MelCloud extends EventEmitter {
|
|
|
283
283
|
async connectToMelCloudHome() {
|
|
284
284
|
let browser;
|
|
285
285
|
try {
|
|
286
|
-
browser = await puppeteer.launch({
|
|
287
|
-
headless: true,
|
|
288
|
-
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
289
|
-
});
|
|
290
|
-
|
|
286
|
+
browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
|
|
291
287
|
const page = await browser.newPage();
|
|
292
|
-
await page.goto(ApiUrlsHome.BaseURL, { waitUntil: 'networkidle2' });
|
|
293
288
|
|
|
294
|
-
//
|
|
289
|
+
// 1. Otwórz stronę logowania
|
|
290
|
+
await page.goto('https://app.melcloud.com/Mitsubishi.Wifi.Client/Login', { waitUntil: 'networkidle2' });
|
|
291
|
+
|
|
292
|
+
// 2. Kliknij login (jeżeli strona główna ma przycisk)
|
|
293
|
+
// Zastąp fragment z page.$x
|
|
295
294
|
const buttons = await page.$$('button.btn--blue');
|
|
296
295
|
let loginBtn = null;
|
|
297
296
|
|
|
@@ -309,45 +308,31 @@ class MelCloud extends EventEmitter {
|
|
|
309
308
|
page.waitForNavigation({ waitUntil: 'networkidle2' })
|
|
310
309
|
]);
|
|
311
310
|
|
|
312
|
-
//
|
|
313
|
-
await page.
|
|
314
|
-
await page.type('input[name="
|
|
311
|
+
// 3. Wypełnij login i hasło
|
|
312
|
+
await page.waitForSelector('input[name="username"]', { timeout: 5000 });
|
|
313
|
+
await page.type('input[name="username"]', user, { delay: 50 });
|
|
314
|
+
await page.type('input[name="password"]', passwd, { delay: 50 });
|
|
315
315
|
|
|
316
|
-
// Kliknięcie submit
|
|
317
316
|
const submitBtn = await page.$('input[type="submit"]');
|
|
318
|
-
|
|
319
|
-
await Promise.all([
|
|
320
|
-
submitBtn.click(),
|
|
321
|
-
page.waitForNavigation({ waitUntil: 'networkidle2' })
|
|
322
|
-
]);
|
|
317
|
+
await submitBtn?.click();
|
|
323
318
|
|
|
324
|
-
//
|
|
319
|
+
// 4. Czekamy na przekierowanie z 'code' w URL
|
|
320
|
+
await page.waitForFunction(() => window.location.href.includes('code'), { timeout: 15000 });
|
|
325
321
|
const currentUrl = page.url();
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
//
|
|
331
|
-
await
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
params.append('redirect_uri', 'melcloudhome://');
|
|
339
|
-
|
|
340
|
-
const tokenResp = await fetch('https://auth.melcloudhome.com/connect/token', {
|
|
341
|
-
method: 'POST',
|
|
342
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
343
|
-
body: params.toString()
|
|
322
|
+
const authCode = new URL(currentUrl).searchParams.get('code');
|
|
323
|
+
|
|
324
|
+
if (!authCode) throw new Error('Authorization code not found in URL');
|
|
325
|
+
|
|
326
|
+
// 5. Wymień code na access_token
|
|
327
|
+
const tokenResponse = await axios.post('https://app.melcloud.com/Mitsubishi.Wifi.Client/OAuth/Token', new URLSearchParams({
|
|
328
|
+
client_id: clientId,
|
|
329
|
+
grant_type: 'authorization_code',
|
|
330
|
+
code: authCode,
|
|
331
|
+
redirect_uri: 'melcloudhome://'
|
|
332
|
+
}).toString(), {
|
|
333
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
344
334
|
});
|
|
345
335
|
|
|
346
|
-
if (!tokenResp.ok) {
|
|
347
|
-
const errText = await tokenResp.text();
|
|
348
|
-
throw new Error(`Token request failed: ${errText}`);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
336
|
const tokenData = await tokenResp.json();
|
|
352
337
|
this.emit('debug', `Token: ${JSON.stringify(tokenData, null, 2)}`);
|
|
353
338
|
return {
|