homebridge-melcloud-control 4.10.8 → 4.10.9-beta.1

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.
@@ -268,10 +268,16 @@
268
268
  updateInfo('info2', '', fontColor);
269
269
  homebridge.showSpinner();
270
270
 
271
+ const statusListener = event => updateInfo('info', event.data, fontColor);
272
+ homebridge.addEventListener('status', statusListener);
273
+
271
274
  try {
272
275
  const account = this.account;
273
276
  const accountTypeMelcloud = account.type === 'melcloud';
274
- const melCloudDevicesData = await homebridge.request('/connect', account);
277
+ const connectTimeout = new Promise((_, reject) =>
278
+ setTimeout(() => reject(new Error('Connection timed out — please try again')), 160_000)
279
+ );
280
+ const melCloudDevicesData = await Promise.race([homebridge.request('/connect', account), connectTimeout]);
275
281
 
276
282
  if (!melCloudDevicesData.State) {
277
283
  updateInfo('info', melCloudDevicesData.Status, 'red');
@@ -448,9 +454,11 @@
448
454
  await homebridge.updatePluginConfig(pluginConfig);
449
455
  await homebridge.savePluginConfig(pluginConfig);
450
456
  } catch (error) {
451
- updateInfo('info', `Prepare config error`, "red");
452
- updateInfo('info1', `Error: ${JSON.stringify(error)}`, "red");
457
+ const msg = error?.message || error?.error || String(error);
458
+ updateInfo('info', 'Connection failed', 'red');
459
+ updateInfo('info1', msg, 'red');
453
460
  } finally {
461
+ homebridge.removeEventListener('status', statusListener);
454
462
  homebridge.hideSpinner();
455
463
  $('logIn').disabled = false;
456
464
  }
@@ -13,17 +13,26 @@ class PluginUiServer extends HomebridgePluginUiServer {
13
13
  this.ready();
14
14
  };
15
15
 
16
+ withTimeout(promise, ms, label) {
17
+ const timer = new Promise((_, reject) =>
18
+ setTimeout(() => reject(new Error(`${label} timed out after ${ms / 1000}s`)), ms)
19
+ );
20
+ return Promise.race([promise, timer]);
21
+ }
22
+
16
23
  async start(account) {
17
24
  const melCloudClass = account.type === 'melcloud' ? new MelCloud(account) : new MelCloudHome(account);
18
25
 
19
26
  try {
20
- const melCloudAccountData = await melCloudClass.connect();
27
+ this.pushEvent('status', 'Connecting to account...');
28
+ const melCloudAccountData = await this.withTimeout(melCloudClass.connect(), 90_000, 'connect');
21
29
  if (!melCloudAccountData.State) return melCloudAccountData;
22
30
 
23
- const melCloudDevicesData = await melCloudClass.checkDevicesList();
31
+ this.pushEvent('status', 'Loading devices...');
32
+ const melCloudDevicesData = await this.withTimeout(melCloudClass.checkDevicesList(), 60_000, 'checkDevicesList');
24
33
  return melCloudDevicesData;
25
34
  } catch (error) {
26
- throw new Error(error);
35
+ throw new Error(error.message ?? String(error));
27
36
  }
28
37
  }
29
38
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.10.8",
4
+ "version": "4.10.9-beta.1",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -35,7 +35,7 @@
35
35
  "node": "^20 || ^22 || ^24 || ^25 || ^26"
36
36
  },
37
37
  "dependencies": {
38
- "@homebridge/plugin-ui-utils": "^2.2.3",
38
+ "@homebridge/plugin-ui-utils": "^2.2.4",
39
39
  "mqtt": "^5.15.1",
40
40
  "axios": "^1.16.1",
41
41
  "axios-cookiejar-support": "^7.0.0",