homebridge-melcloud-control 4.0.0-beta.514 → 4.0.0-beta.516

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/index.js CHANGED
@@ -112,14 +112,17 @@ class MelCloudPlatform {
112
112
  const useFahrenheit = accountInfo.UseFahrenheit;
113
113
 
114
114
  //check devices list
115
- let devicesInMelcloud;
115
+ let devicesList;
116
116
  try {
117
- devicesInMelcloud = await melCloud.checkDevicesList();
117
+ devicesList = await melCloud.checkDevicesList();
118
118
  } catch (error) {
119
119
  if (logLevel.error) log.error(`${accountName}, Check devices list error: ${error.message ?? error}`);
120
120
  return;
121
121
  }
122
- if (!devicesInMelcloud || !Array.isArray(devicesInMelcloud)) return;
122
+ if (!devicesList.State) {
123
+ if (logLevel.warn) log.warn(`${accountName}, ${devicesList.Info}`);
124
+ return;
125
+ }
123
126
 
124
127
  //configured devices
125
128
  const ataDevices = account.ataDevices ?? [];
@@ -131,7 +134,7 @@ class MelCloudPlatform {
131
134
  for (const device of devices) {
132
135
  //chack device from config exist on melcloud
133
136
  const displayType = device.displayType > 0;
134
- const deviceExistInMelCloud = devicesInMelcloud.some(dev => dev.DeviceID === device.id);
137
+ const deviceExistInMelCloud = devicesList.Devices.some(dev => dev.DeviceID === device.id);
135
138
  if (!deviceExistInMelCloud || !displayType) {
136
139
  continue;
137
140
  }
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.514",
4
+ "version": "4.0.0-beta.516",
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
@@ -63,6 +63,7 @@ class MelCloud extends EventEmitter {
63
63
  // MELCloud
64
64
  async checkMelcloudDevicesList() {
65
65
  try {
66
+ const devicesList = { State: false, Info: null, Devices: [] }
66
67
  const axiosInstance = axios.create({
67
68
  method: 'GET',
68
69
  baseURL: ApiUrls.BaseURL,
@@ -92,8 +93,6 @@ class MelCloud extends EventEmitter {
92
93
  await this.functions.saveData(this.buildingsFile, buildingsList);
93
94
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
94
95
 
95
- const devices = [];
96
-
97
96
  for (const building of buildingsList) {
98
97
  if (!building.Structure) {
99
98
  this.emit('warn', `Building missing structure: ${building.BuildingName || 'Unnamed'}`);
@@ -121,18 +120,22 @@ class MelCloud extends EventEmitter {
121
120
  this.emit('debug', `Found ${count} devices in building: ${building.Name || 'Unnamed'}`);
122
121
  }
123
122
 
124
- devices.push(...allDevices);
123
+ devicesList.Devices.push(...allDevices);
125
124
  }
126
125
 
127
- if (devices.length === 0) {
128
- if (this.logWarn) this.emit('warn', `No devices found in any building`);
129
- return null;
126
+ const devicesCount = devicesList.Devices.length;
127
+ if (devicesCount === 0) {
128
+ devicesList.State = false;
129
+ devicesList.Info = 'No devices found'
130
+ return devicesList;
130
131
  }
131
132
 
132
- await this.functions.saveData(this.devicesFile, devices);
133
- if (this.logDebug) this.emit('debug', `${devices.length} devices saved`);
133
+ await this.functions.saveData(this.devicesFile, devicesList.Devices);
134
+ if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
134
135
 
135
- return devices;
136
+ devicesList.State = true;
137
+ devicesList.Info = `Found ${devicesCount} devices`;
138
+ return devicesList;
136
139
  } catch (error) {
137
140
  const msg = error.response ? `HTTP ${error.response.status}: ${error.response.statusText}` : error.message;
138
141
  throw new Error(`Check devices list error: ${msg}`);
@@ -200,6 +203,7 @@ class MelCloud extends EventEmitter {
200
203
  // MELCloud Home
201
204
  async checkMelcloudHomeDevicesList() {
202
205
  try {
206
+ const devicesList = { State: false, Info: null, Devices: [] }
203
207
  const axiosInstance = axios.create({
204
208
  method: 'GET',
205
209
  baseURL: ApiUrlsHome.BaseURL,
@@ -225,8 +229,9 @@ class MelCloud extends EventEmitter {
225
229
  if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
226
230
 
227
231
  if (!buildingsList) {
228
- if (this.logWarn) this.emit('warn', `No building found`);
229
- return null;
232
+ devicesList.State = false;
233
+ devicesList.Info = 'No building found'
234
+ return devicesList;
230
235
  }
231
236
 
232
237
  await this.functions.saveData(this.buildingsFile, buildingsList);
@@ -288,14 +293,18 @@ class MelCloud extends EventEmitter {
288
293
 
289
294
  const devicesCount = devices.length;
290
295
  if (devicesCount === 0) {
291
- if (this.logWarn) this.emit('warn', `No devices found`);
292
- return null;
296
+ devicesList.State = false;
297
+ devicesList.Info = 'No devices found'
298
+ return devicesList;
293
299
  }
294
300
 
295
301
  await this.functions.saveData(this.devicesFile, devices);
296
302
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
297
303
 
298
- return devices;
304
+ devicesList.State = true;
305
+ devicesList.Info = `Found ${devicesCount} devices`;
306
+ devicesList.Devices = devices;
307
+ return devicesList;
299
308
  } catch (error) {
300
309
  throw new Error(`Check devices list error: ${error.message}`);
301
310
  }