homebridge-melcloud-control 4.0.0-beta.491 → 4.0.0-beta.493

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.
@@ -230,10 +230,10 @@
230
230
 
231
231
  try {
232
232
  const account = pluginConfig[0].accounts[this.accountIndex];
233
- const devicesInMelCloud = await homebridge.request('/connect', account);
234
- if (devicesInMelCloud === 'No chromium installed') {
233
+ const response = await homebridge.request('/connect', account);
234
+ if (!response.State) {
235
235
  homebridge.hideSpinner();
236
- updateInfo('info', 'Chromium not found on Your device, please install it manually and try again.', 'Red');
236
+ updateInfo('info', response.Info);
237
237
  return;
238
238
  }
239
239
 
@@ -241,7 +241,7 @@
241
241
  const newDevices = { ata: [], ataPresets: [], atw: [], atwPresets: [], erv: [], ervPresets: [] };
242
242
  const devicesByType = { ata: [], atw: [], erv: [] };
243
243
 
244
- devicesInMelCloud.forEach(d => {
244
+ response.forEach(d => {
245
245
  if (d.Type === 0) devicesByType.ata.push(d);
246
246
  if (d.Type === 1) devicesByType.atw.push(d);
247
247
  if (d.Type === 3) devicesByType.erv.push(d);
@@ -21,6 +21,8 @@ class PluginUiServer extends HomebridgePluginUiServer {
21
21
 
22
22
  try {
23
23
  const accountInfo = await melCloud.connect();
24
+ if (!accountInfo.State) return accountInfo;
25
+
24
26
  const devices = await melCloud.checkDevicesList();
25
27
  return devices;
26
28
  } catch (error) {
package/index.js CHANGED
@@ -105,6 +105,11 @@ class MelCloudPlatform {
105
105
  return;
106
106
  }
107
107
 
108
+ if (!accountInfo.State) {
109
+ if (logLevel.warn) log.warn(`${accountName}, Connect not possible: ${accountInfo.Info}`);
110
+ return;
111
+ }
112
+
108
113
  const contextKey = accountInfo.ContextKey;
109
114
  const useFahrenheit = accountInfo.UseFahrenheit;
110
115
 
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.491",
4
+ "version": "4.0.0-beta.493",
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
@@ -140,13 +140,14 @@ class MelCloud extends EventEmitter {
140
140
  if (this.logDebug) this.emit('debug', `Connecting to MELCloud`);
141
141
 
142
142
  try {
143
+ const accountInfo = { State: false, Info: '', ContextKey: null, UseFahrenheit: false }
143
144
  const axiosInstance = axios.create({
144
145
  method: 'POST',
145
146
  baseURL: ApiUrls.BaseURL,
146
147
  timeout: 15000,
147
148
  });
148
149
 
149
- const loginData = {
150
+ const data = {
150
151
  Email: this.user,
151
152
  Password: this.passwd,
152
153
  Language: this.language,
@@ -156,14 +157,14 @@ class MelCloud extends EventEmitter {
156
157
  Persist: true
157
158
  };
158
159
 
159
- const accountData = await axiosInstance(ApiUrls.ClientLogin, { data: loginData });
160
+ const accountData = await axiosInstance(ApiUrls.ClientLogin, { data: data });
160
161
  const account = accountData.data;
161
- const accountInfo = account.LoginData ?? [];
162
- const contextKey = accountInfo.ContextKey;
162
+ const loginData = account.LoginData ?? [];
163
+ const contextKey = LoginData.ContextKey;
163
164
  this.contextKey = contextKey;
164
165
 
165
166
  const debugData = {
166
- ...accountInfo,
167
+ ...loginData,
167
168
  ContextKey: 'removed',
168
169
  ClientId: 'removed',
169
170
  Client: 'removed',
@@ -175,9 +176,16 @@ class MelCloud extends EventEmitter {
175
176
 
176
177
  if (!contextKey) {
177
178
  if (this.logWarn) this.emit('warn', `Context key missing`);
178
- return null;
179
+ accountInfo.State = false;
180
+ accountInfo.Info = 'Context key missing'
181
+ return accountInfo;
179
182
  }
180
183
 
184
+ accountInfo.State = true;
185
+ accountInfo.Info = 'Connect success';
186
+ accountInfo.LoginData = loginData;
187
+ accountInfo.ContextKey = contextKey;
188
+
181
189
  await this.functions.saveData(this.accountFile, accountInfo);
182
190
  this.emit('success', `Connect to MELCloud Success`);
183
191
 
@@ -297,10 +305,13 @@ class MelCloud extends EventEmitter {
297
305
  let browser;
298
306
 
299
307
  try {
308
+ const accountInfo = { State: false, Info: '', ContextKey: null, UseFahrenheit: false }
300
309
  const chromiumPath = await this.functions.ensureChromiumInstalled();
301
310
  if (!chromiumPath) {
302
- if (this.logWarn) this.emit('warn', 'Chromium not found on Your device, please install it manually and try again.');
303
- return 'No chromium installed';
311
+ if (this.logWarn) this.emit('warn', 'Chromium not found on Your device, please install it manually and try again');
312
+ accountInfo.State = false;
313
+ accountInfo.Info = 'Chromium not found on Your device, please install it manually and try again'
314
+ return accountInfo;
304
315
  }
305
316
 
306
317
  this.emit('warn', `Test 1`);
@@ -325,7 +336,7 @@ class MelCloud extends EventEmitter {
325
336
  const pages = await browser.pages();
326
337
  let page = pages[0];
327
338
  if (!page) {
328
- if (this.logWarn) this.emit('warn', 'No initial page found, creating a new one.');
339
+ if (this.logWarn) this.emit('warn', 'No initial page found, creating a new one');
329
340
  page = await browser.newPage();
330
341
  await new Promise(r => setTimeout(r, 2000));
331
342
  }
@@ -353,20 +364,21 @@ class MelCloud extends EventEmitter {
353
364
  }, { timeout: 5000 }); // max 5s czekania
354
365
  } catch {
355
366
  if (this.logWarn) this.emit('warn', 'Login button not found after 5s');
356
- return null;
367
+ accountInfo.State = false;
368
+ accountInfo.Info = 'Login button not found after 5s';
369
+ return accountInfo;
357
370
  }
358
371
 
359
- await Promise.race([
360
- Promise.all([loginBtn.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 15000 })]),
361
- new Promise(r => setTimeout(r, 12000))
362
- ]);
372
+ await Promise.race([Promise.all([loginBtn.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 10000 })]), new Promise(r => setTimeout(r, 8000))]);
363
373
 
364
374
  this.emit('warn', `Test 7`);
365
375
  const usernameInput = await page.$('input[name="username"]');
366
376
  const passwordInput = await page.$('input[name="password"]');
367
377
  if (!usernameInput || !passwordInput) {
368
378
  if (this.logWarn) this.emit('warn', 'Username or password input not found');
369
- return null;
379
+ accountInfo.State = false;
380
+ accountInfo.Info = 'Username or password input not found';
381
+ return accountInfo;
370
382
  }
371
383
 
372
384
  this.emit('warn', `Test 8`);
@@ -377,13 +389,12 @@ class MelCloud extends EventEmitter {
377
389
  const submitButton = await page.$('input[type="submit"], button[type="submit"]');
378
390
  if (!submitButton) {
379
391
  if (this.logWarn) this.emit('warn', 'Submit button not found on login form');
380
- return null;
392
+ accountInfo.State = false;
393
+ accountInfo.Info = 'Submit button not found on login form';
394
+ return accountInfo;
381
395
  }
382
396
 
383
- await Promise.race([
384
- Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 20000 })]),
385
- new Promise(r => setTimeout(r, 15000))
386
- ]);
397
+ await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 10000 })]), new Promise(r => setTimeout(r, 8000))]);
387
398
 
388
399
  this.emit('warn', `Test 10`);
389
400
  let c1 = null, c2 = null;
@@ -398,7 +409,9 @@ class MelCloud extends EventEmitter {
398
409
  this.emit('warn', `Test 11`);
399
410
  if (!c1 || !c2) {
400
411
  if (this.logWarn) this.emit('warn', 'Cookies C1/C2 missing after login');
401
- return null;
412
+ accountInfo.State = false;
413
+ accountInfo.Info = 'Cookies C1/C2 missing after login';
414
+ return accountInfo;
402
415
  }
403
416
 
404
417
  const contextKey = [
@@ -406,10 +419,12 @@ class MelCloud extends EventEmitter {
406
419
  `__Secure-monitorandcontrolC1=${c1}`,
407
420
  `__Secure-monitorandcontrolC2=${c2}`
408
421
  ].join('; ');
409
-
410
- const accountInfo = { ContextKey: contextKey, UseFahrenheit: false };
411
422
  this.contextKey = contextKey;
412
423
 
424
+ accountInfo.State = true;
425
+ accountInfo.Info = 'Connect success';
426
+ accountInfo.ContextKey = contextKey;
427
+
413
428
  this.emit('warn', `Test 12`);
414
429
  await this.functions.saveData(this.accountFile, accountInfo);
415
430
 
@@ -450,7 +465,7 @@ class MelCloud extends EventEmitter {
450
465
  }
451
466
 
452
467
  async connect(refresh) {
453
- const TIMEOUT_MS = 75000;
468
+ const TIMEOUT_MS = 60000;
454
469
 
455
470
  try {
456
471
  const result = await Promise.race([
@@ -464,7 +479,7 @@ class MelCloud extends EventEmitter {
464
479
  return {};
465
480
  }
466
481
  })(),
467
- new Promise((_, reject) => setTimeout(() => reject(new Error('Connection timeout (75s)')), TIMEOUT_MS))
482
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Connection timeout (60s)')), TIMEOUT_MS))
468
483
  ]);
469
484
 
470
485
  return result;