homebridge-melcloud-control 4.0.0-beta.21 → 4.0.0-beta.22
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 +42 -22
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.22",
|
|
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
|
@@ -213,17 +213,51 @@ class MelCloud extends EventEmitter {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
async
|
|
216
|
+
async loginToMelcloudHome() {
|
|
217
217
|
try {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
const form = new URLSearchParams();
|
|
219
|
+
form.append('user[email]', this.user);
|
|
220
|
+
form.append('user[password]', this.passwd);
|
|
221
|
+
|
|
222
|
+
const response = await axios({
|
|
223
|
+
method: 'POST',
|
|
224
|
+
baseURL: EnphaseUrls.BaseUrl,
|
|
225
|
+
url: EnphaseUrls.Login,
|
|
226
|
+
headers: {
|
|
227
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
228
|
+
},
|
|
229
|
+
data: form,
|
|
230
|
+
timeout: 10000
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
if (response.status !== 200) {
|
|
234
|
+
if (this.logError) this.emit('error', `Login failed with status code: ${response.status}`);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const cookie = response.headers['set-cookie'];
|
|
239
|
+
if (!cookie) {
|
|
240
|
+
if (this.logWarn) this.emit('warn', `No cookie returned from login. Response headers: ${JSON.stringify(response.headers)}`);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
221
243
|
|
|
244
|
+
return cookie;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
throw new Error(`Login to Enlighten error: ${error}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async connectHomeCookies() {
|
|
251
|
+
const loginUrl = 'https://melcloudhome.com';
|
|
252
|
+
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
|
|
253
|
+
const page = await browser.newPage();
|
|
254
|
+
|
|
255
|
+
try {
|
|
222
256
|
this.emit('warn', 'Opening login page...');
|
|
223
257
|
await page.goto(loginUrl, { waitUntil: 'networkidle2' });
|
|
224
258
|
|
|
225
259
|
// Kliknij przycisk logowania
|
|
226
|
-
const buttons = await page.$$('button.btn--blue');
|
|
260
|
+
const buttons = await page.$$('button.btn--blue');
|
|
227
261
|
let loginBtn = null;
|
|
228
262
|
for (const btn of buttons) {
|
|
229
263
|
const text = await page.evaluate(el => el.textContent, btn);
|
|
@@ -254,25 +288,11 @@ class MelCloud extends EventEmitter {
|
|
|
254
288
|
page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 20000 })
|
|
255
289
|
]);
|
|
256
290
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
// Loop max 20s, czekamy aż pojawią się cookies
|
|
261
|
-
while ((!c1 || !c2) && Date.now() - start < 20000) {
|
|
262
|
-
const cookies = await page.cookies();
|
|
263
|
-
c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || c1;
|
|
264
|
-
c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || c2;
|
|
265
|
-
if (!c1 || !c2) await new Promise(r => setTimeout(r, 500));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (!c1 || !c2) {
|
|
269
|
-
await browser.close();
|
|
270
|
-
throw new Error('❌ Cookies C1/C2 not found after login');
|
|
271
|
-
}
|
|
291
|
+
const cookies = await page.cookies();
|
|
292
|
+
this.emit('warn', cookies);
|
|
272
293
|
|
|
273
294
|
// Zapis do pliku
|
|
274
|
-
|
|
275
|
-
await this.functions.saveData(this.cookiesFile, data);
|
|
295
|
+
await this.functions.saveData(this.cookiesFile, cookies);
|
|
276
296
|
|
|
277
297
|
this.emit('warn', 'Login successful.');
|
|
278
298
|
return data;
|