homebridge-melcloud-control 4.0.0-beta.492 → 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.492",
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,7 +364,9 @@ 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
372
  await Promise.race([Promise.all([loginBtn.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 10000 })]), new Promise(r => setTimeout(r, 8000))]);
@@ -363,7 +376,9 @@ class MelCloud extends EventEmitter {
363
376
  const passwordInput = await page.$('input[name="password"]');
364
377
  if (!usernameInput || !passwordInput) {
365
378
  if (this.logWarn) this.emit('warn', 'Username or password input not found');
366
- return null;
379
+ accountInfo.State = false;
380
+ accountInfo.Info = 'Username or password input not found';
381
+ return accountInfo;
367
382
  }
368
383
 
369
384
  this.emit('warn', `Test 8`);
@@ -374,7 +389,9 @@ class MelCloud extends EventEmitter {
374
389
  const submitButton = await page.$('input[type="submit"], button[type="submit"]');
375
390
  if (!submitButton) {
376
391
  if (this.logWarn) this.emit('warn', 'Submit button not found on login form');
377
- return null;
392
+ accountInfo.State = false;
393
+ accountInfo.Info = 'Submit button not found on login form';
394
+ return accountInfo;
378
395
  }
379
396
 
380
397
  await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: 10000 })]), new Promise(r => setTimeout(r, 8000))]);
@@ -392,7 +409,9 @@ class MelCloud extends EventEmitter {
392
409
  this.emit('warn', `Test 11`);
393
410
  if (!c1 || !c2) {
394
411
  if (this.logWarn) this.emit('warn', 'Cookies C1/C2 missing after login');
395
- return null;
412
+ accountInfo.State = false;
413
+ accountInfo.Info = 'Cookies C1/C2 missing after login';
414
+ return accountInfo;
396
415
  }
397
416
 
398
417
  const contextKey = [
@@ -400,10 +419,12 @@ class MelCloud extends EventEmitter {
400
419
  `__Secure-monitorandcontrolC1=${c1}`,
401
420
  `__Secure-monitorandcontrolC2=${c2}`
402
421
  ].join('; ');
403
-
404
- const accountInfo = { ContextKey: contextKey, UseFahrenheit: false };
405
422
  this.contextKey = contextKey;
406
423
 
424
+ accountInfo.State = true;
425
+ accountInfo.Info = 'Connect success';
426
+ accountInfo.ContextKey = contextKey;
427
+
407
428
  this.emit('warn', `Test 12`);
408
429
  await this.functions.saveData(this.accountFile, accountInfo);
409
430