homebridge-melcloud-control 4.2.5-beta.9 → 4.2.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.
@@ -9,7 +9,7 @@ import Functions from './functions.js';
9
9
  import { ApiUrlsHome, LanguageLocaleMap } from './constants.js';
10
10
  const execPromise = promisify(exec);
11
11
 
12
- class MelCloud extends EventEmitter {
12
+ class MelCloudHome extends EventEmitter {
13
13
  constructor(account, accountFile, buildingsFile, devicesFile, pluginStart = false) {
14
14
  super();
15
15
  this.accountType = account.type;
@@ -61,7 +61,6 @@ class MelCloud extends EventEmitter {
61
61
  }
62
62
  }
63
63
 
64
- // MELCloud Home
65
64
  async checkScenesList() {
66
65
  try {
67
66
  if (this.logDebug) this.emit('debug', `Scanning for scenes`);
@@ -195,10 +194,17 @@ class MelCloud extends EventEmitter {
195
194
  return devicesList;
196
195
  }
197
196
 
198
- const scenes = await this.checkScenesList();
197
+ // Get scenes
198
+ let scenes = [];
199
+ try {
200
+ scenes = await this.checkScenesList();
201
+ if (this.logDebug) this.emit('debug', `Found ${scenes.length} svenes`);
202
+ } catch (error) {
203
+ if (this.logDebug) this.emit('debug', `Get scenes error: ${error} `);
204
+ }
199
205
 
200
206
  devicesList.State = true;
201
- devicesList.Info = `Found ${devicesCount} devices`;
207
+ devicesList.Info = `Found ${devicesCount} devices and ${scenes.length} scenes`;
202
208
  devicesList.Devices = devices;
203
209
  devicesList.Scenes = scenes;
204
210
  devicesList.Headers = this.headers;
@@ -208,12 +214,6 @@ class MelCloud extends EventEmitter {
208
214
 
209
215
  return devicesList;
210
216
  } catch (error) {
211
- if (error.response?.status === 401) {
212
- if (this.logWarn) this.emit('warn', 'Check devices list not possible, cookies expired, trying to get new.');
213
- await this.connect();
214
- return;
215
- }
216
-
217
217
  throw new Error(`Check devices list error: ${error.message}`);
218
218
  }
219
219
  }
@@ -224,7 +224,7 @@ class MelCloud extends EventEmitter {
224
224
 
225
225
  let browser;
226
226
  try {
227
- const accountInfo = { State: false, Info: '', Headers: {}, UseFahrenheit: false };
227
+ const accountInfo = { State: false, Info: '', Account: {}, UseFahrenheit: false };
228
228
  let chromiumPath = await this.functions.ensureChromiumInstalled();
229
229
 
230
230
  // === Fallback to Puppeteer's built-in Chromium ===
@@ -276,14 +276,6 @@ class MelCloud extends EventEmitter {
276
276
  page.setDefaultTimeout(GLOBAL_TIMEOUT);
277
277
  page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
278
278
 
279
- // Clear cookies before navigation
280
- try {
281
- const client = await page.createCDPSession();
282
- await client.send('Network.clearBrowserCookies');
283
- } catch (error) {
284
- if (this.logError) this.emit('error', `Clear cookies error: ${error.message}`);
285
- }
286
-
287
279
  try {
288
280
  await page.goto(ApiUrlsHome.BaseURL, { waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT });
289
281
  } catch (error) {
@@ -293,7 +285,7 @@ class MelCloud extends EventEmitter {
293
285
 
294
286
  // Wait extra to ensure UI is rendered
295
287
  await new Promise(r => setTimeout(r, 3000));
296
- const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT / 4 });
288
+ const loginBtn = await page.waitForSelector('button.btn--blue', { timeout: GLOBAL_TIMEOUT / 3 });
297
289
  const loginText = await page.evaluate(el => el.textContent.trim(), loginBtn);
298
290
 
299
291
  if (!['Zaloguj', 'Sign In', 'Login'].includes(loginText)) {
@@ -319,13 +311,13 @@ class MelCloud extends EventEmitter {
319
311
  accountInfo.Info = 'Submit button not found';
320
312
  return accountInfo;
321
313
  }
322
- await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 4 })]), new Promise(r => setTimeout(r, GLOBAL_TIMEOUT / 3))]);
314
+ await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 3 })]), new Promise(r => setTimeout(r, GLOBAL_TIMEOUT / 3))]);
323
315
 
324
316
  // Extract cookies
325
317
  let c1 = null, c2 = null;
326
318
  const start = Date.now();
327
319
  while ((!c1 || !c2) && Date.now() - start < GLOBAL_TIMEOUT / 2) {
328
- const cookies = await page.browserContext().cookies();
320
+ const cookies = await browser.cookies();
329
321
  c1 = cookies.find(c => c.name === '__Secure-monitorandcontrolC1')?.value || c1;
330
322
  c2 = cookies.find(c => c.name === '__Secure-monitorandcontrolC2')?.value || c2;
331
323
  if (!c1 || !c2) await new Promise(r => setTimeout(r, 500));
@@ -342,8 +334,8 @@ class MelCloud extends EventEmitter {
342
334
  `__Secure-monitorandcontrolC2=${c2}`
343
335
  ].join('; ');
344
336
 
337
+
345
338
  const userAgent = await page.evaluate(() => navigator.userAgent);
346
- this.emit('warn', `UserAgent: ${userAgent}`);
347
339
  const headers = {
348
340
  'Accept': '*/*',
349
341
  'Accept-Encoding': 'gzip, deflate, br',
@@ -380,17 +372,7 @@ class MelCloud extends EventEmitter {
380
372
  }
381
373
  }
382
374
  }
383
-
384
- async send(accountInfo) {
385
- try {
386
- //await this.axiosInstance(ApiUrlsHome.UpdateApplicationOptions, { method: 'POST' });
387
- //await this.functions.saveData(this.accountFile, accountInfo);
388
- return true;
389
- } catch (error) {
390
- throw new Error(`Send data error: ${error.message}`);
391
- }
392
- }
393
375
  }
394
376
 
395
- export default MelCloud;
377
+ export default MelCloudHome;
396
378