homebridge-melcloud-control 4.2.3-beta.22 → 4.2.3-beta.23

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.2.3-beta.22",
4
+ "version": "4.2.3-beta.23",
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
@@ -86,6 +86,7 @@ class MelCloud extends EventEmitter {
86
86
  await this.functions.saveData(this.buildingsFile, buildingsList);
87
87
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
88
88
 
89
+ const devices = [];
89
90
  for (const building of buildingsList) {
90
91
  if (!building.Structure) {
91
92
  this.emit('warn', `Building missing structure: ${building.BuildingName || 'Unnamed'}`);
@@ -110,20 +111,21 @@ class MelCloud extends EventEmitter {
110
111
  });
111
112
 
112
113
  if (this.logDebug) this.emit('debug', `Found ${allDevices.length} devices in building: ${building.Name || 'Unnamed'}`);
113
- devicesList.Devices.push(...allDevices);
114
+ devices.push(...allDevices);
114
115
  }
115
116
 
116
- const devicesCount = devicesList.Devices.length;
117
+ const devicesCount = devices.length;
117
118
  if (devicesCount === 0) {
118
119
  devicesList.Info = 'No devices found'
119
120
  return devicesList;
120
121
  }
122
+ devicesList.State = true;
123
+ devicesList.Info = `Found ${devicesCount} devices`;
124
+ devicesList.Devices = devices;
121
125
 
122
- await this.functions.saveData(this.devicesFile, devicesList.Devices);
126
+ await this.functions.saveData(this.devicesFile, devicesList);
123
127
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
124
128
 
125
- devicesList.State = true;
126
- devicesList.Info = `Found ${devicesCount} devices`;
127
129
  return devicesList;
128
130
  } catch (error) {
129
131
  throw new Error(`Check devices list error: ${error.message}`);
@@ -52,7 +52,7 @@ class MelCloudAta extends EventEmitter {
52
52
  try {
53
53
  //read device info from file
54
54
  const devicesData = await this.functions.readData(this.devicesFile, true);
55
- const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
55
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
56
56
 
57
57
  if (this.accountType === 'melcloudhome') {
58
58
  deviceData.Device.OperationMode = AirConditioner.OperationModeMapStringToEnum[deviceData.Device.OperationMode] ?? deviceData.Device.OperationMode;
@@ -52,7 +52,7 @@ class MelCloudAtw extends EventEmitter {
52
52
  try {
53
53
  //read device info from file
54
54
  const devicesData = await this.functions.readData(this.devicesFile, true);
55
- const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
55
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
56
56
 
57
57
  if (this.accountType === 'melcloudhome') {
58
58
  }
@@ -52,7 +52,7 @@ class MelCloudErv extends EventEmitter {
52
52
  try {
53
53
  //read device info from file
54
54
  const devicesData = await this.functions.readData(this.devicesFile, true);
55
- const deviceData = devicesData.find(device => device.DeviceID === this.deviceId);
55
+ const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
56
56
 
57
57
  if (this.accountType === 'melcloudhome') {
58
58
  //read default temps
@@ -166,12 +166,13 @@ class MelCloud extends EventEmitter {
166
166
  return devicesList;
167
167
  }
168
168
 
169
- await this.functions.saveData(this.devicesFile, devices);
170
- if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
171
-
172
169
  devicesList.State = true;
173
170
  devicesList.Info = `Found ${devicesCount} devices`;
174
171
  devicesList.Devices = devices;
172
+
173
+ await this.functions.saveData(this.devicesFile, devicesList);
174
+ if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
175
+
175
176
  return devicesList;
176
177
  } catch (error) {
177
178
  if (error.response?.status === 401) {