homebridge-melcloud-control 4.0.0-beta.4 → 4.0.0-beta.5
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/index.js +1 -1
- package/package.json +1 -1
- package/src/melcloud.js +55 -59
package/index.js
CHANGED
|
@@ -76,7 +76,7 @@ class MelCloudPlatform {
|
|
|
76
76
|
const accountFile = `${prefDir}/${accountName}_Account`;
|
|
77
77
|
const buildingsFile = `${prefDir}/${accountName}_Buildings`;
|
|
78
78
|
const devicesFile = `${prefDir}/${accountName}_Devices`;
|
|
79
|
-
const
|
|
79
|
+
const cookiesFile = `${prefDir}/${accountName}cookies`;
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
//set account refresh interval
|
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.5",
|
|
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
|
@@ -7,7 +7,7 @@ import Functions from './functions.js';
|
|
|
7
7
|
import { ApiUrls, ApiUrlsHome } from './constants.js';
|
|
8
8
|
|
|
9
9
|
class MelCloud extends EventEmitter {
|
|
10
|
-
constructor(user, passwd, language, accountFile, buildingsFile, devicesFile,
|
|
10
|
+
constructor(user, passwd, language, accountFile, buildingsFile, devicesFile, cookiesFile, logWarn, logDebug, requestConfig) {
|
|
11
11
|
super();
|
|
12
12
|
this.user = user;
|
|
13
13
|
this.passwd = passwd;
|
|
@@ -15,7 +15,7 @@ class MelCloud extends EventEmitter {
|
|
|
15
15
|
this.accountFile = accountFile;
|
|
16
16
|
this.buildingsFile = buildingsFile;
|
|
17
17
|
this.devicesFile = devicesFile;
|
|
18
|
-
this.
|
|
18
|
+
this.cookiesFile = cookiesFile;
|
|
19
19
|
this.logWarn = logWarn;
|
|
20
20
|
this.logDebug = logDebug;
|
|
21
21
|
this.requestConfig = requestConfig;
|
|
@@ -213,7 +213,7 @@ class MelCloud extends EventEmitter {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
async
|
|
216
|
+
async connectHomeCookies() {
|
|
217
217
|
const loginUrl = new URL('https://live-melcloudhome.auth.eu-west-1.amazoncognito.com/login');
|
|
218
218
|
loginUrl.searchParams.set('client_id', '3g4d5l5kivuqi7oia68gib7uso');
|
|
219
219
|
loginUrl.searchParams.set('redirect_uri', 'https://auth.melcloudhome.com/signin-oidc-meu');
|
|
@@ -221,8 +221,6 @@ class MelCloud extends EventEmitter {
|
|
|
221
221
|
loginUrl.searchParams.set('scope', 'openid profile');
|
|
222
222
|
loginUrl.searchParams.set('response_mode', 'form_post');
|
|
223
223
|
|
|
224
|
-
|
|
225
|
-
|
|
226
224
|
const browser = await puppeteer.launch({
|
|
227
225
|
headless: true,
|
|
228
226
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
@@ -230,65 +228,63 @@ class MelCloud extends EventEmitter {
|
|
|
230
228
|
|
|
231
229
|
const page = await browser.newPage();
|
|
232
230
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
]);
|
|
262
|
-
buttonFound = true;
|
|
263
|
-
break;
|
|
231
|
+
try {
|
|
232
|
+
this.emit('warn', 'Opening login page...');
|
|
233
|
+
await page.goto(loginUrl.toString(), { waitUntil: 'networkidle2' });
|
|
234
|
+
|
|
235
|
+
this.emit('warn', 'Typing credentials...');
|
|
236
|
+
await page.type('input[name="username"]', this.user, { delay: 50 });
|
|
237
|
+
await page.type('input[name="password"]', this.passwd, { delay: 50 });
|
|
238
|
+
|
|
239
|
+
// Wyszukiwanie przycisku logowania
|
|
240
|
+
const buttonSelectors = [
|
|
241
|
+
'button[type="submit"]',
|
|
242
|
+
'input[type="submit"]',
|
|
243
|
+
'button[name="signIn"]',
|
|
244
|
+
'button.btn-primary'
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
let buttonFound = false;
|
|
248
|
+
for (const selector of buttonSelectors) {
|
|
249
|
+
const button = await page.$(selector);
|
|
250
|
+
if (button) {
|
|
251
|
+
this.emit('warn', `Found submit button: ${selector}`);
|
|
252
|
+
await Promise.all([
|
|
253
|
+
button.click(),
|
|
254
|
+
page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 20000 }) // czekamy na redirect
|
|
255
|
+
]);
|
|
256
|
+
buttonFound = true;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
264
259
|
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (!buttonFound) {
|
|
268
|
-
throw new Error('❌ Could not find login button on the page.');
|
|
269
|
-
}
|
|
270
260
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
// Pobierz cookies dla domeny melcloudhome.com
|
|
276
|
-
const cookies = await page.cookies();
|
|
277
|
-
|
|
278
|
-
// Znajdź __Secure-monitorandcontrolC1 i C2
|
|
279
|
-
const c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || null;
|
|
280
|
-
const c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || null;
|
|
281
|
-
|
|
282
|
-
// Zapisz do pliku
|
|
283
|
-
const data = { C1: c1, C2: c2, date: new Date().toISOString() };
|
|
284
|
-
await this.functions.saveData(this.coociesFile, data);
|
|
261
|
+
if (!buttonFound) {
|
|
262
|
+
throw new Error('❌ Could not find login button on the page.');
|
|
263
|
+
}
|
|
285
264
|
|
|
286
|
-
|
|
265
|
+
// ✅ Poczekaj aż dashboard MELCloud Home będzie gotowy
|
|
266
|
+
this.emit('warn', 'Waiting for MELCloud Home dashboard...');
|
|
267
|
+
await page.waitForSelector('#dashboard, .dashboard-container', { timeout: 20000 });
|
|
268
|
+
|
|
269
|
+
// Pobranie cookies po zalogowaniu
|
|
270
|
+
const cookies = await page.cookies();
|
|
271
|
+
const c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || null;
|
|
272
|
+
const c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || null;
|
|
273
|
+
|
|
274
|
+
const data = { C1: c1, C2: c2, date: new Date().toISOString() };
|
|
275
|
+
await this.functions.saveData(this.cookiesFile, data);
|
|
276
|
+
|
|
277
|
+
this.emit('warn', 'Login successful.');
|
|
278
|
+
return data;
|
|
279
|
+
} catch (err) {
|
|
280
|
+
this.emit('error', `Login failed: ${err.message}`);
|
|
281
|
+
return null;
|
|
282
|
+
} finally {
|
|
283
|
+
await browser.close();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
287
286
|
|
|
288
|
-
this.emit('warn', `Login successful.`);
|
|
289
287
|
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
288
|
|
|
293
289
|
async send(accountInfo) {
|
|
294
290
|
try {
|