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

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.24",
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
@@ -29,13 +29,9 @@ class MelCloud extends EventEmitter {
29
29
  if (pluginStart) {
30
30
  //lock flags
31
31
  this.locks = {
32
- connect: false,
33
32
  checkDevicesList: false
34
33
  };
35
34
  this.impulseGenerator = new ImpulseGenerator()
36
- .on('connect', () => this.handleWithLock('connect', async () => {
37
- await this.connect();
38
- }))
39
35
  .on('checkDevicesList', () => this.handleWithLock('checkDevicesList', async () => {
40
36
  await this.checkDevicesList();
41
37
  }))
@@ -86,6 +82,7 @@ class MelCloud extends EventEmitter {
86
82
  await this.functions.saveData(this.buildingsFile, buildingsList);
87
83
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
88
84
 
85
+ const devices = [];
89
86
  for (const building of buildingsList) {
90
87
  if (!building.Structure) {
91
88
  this.emit('warn', `Building missing structure: ${building.BuildingName || 'Unnamed'}`);
@@ -110,20 +107,22 @@ class MelCloud extends EventEmitter {
110
107
  });
111
108
 
112
109
  if (this.logDebug) this.emit('debug', `Found ${allDevices.length} devices in building: ${building.Name || 'Unnamed'}`);
113
- devicesList.Devices.push(...allDevices);
110
+ devices.push(...allDevices);
114
111
  }
115
112
 
116
- const devicesCount = devicesList.Devices.length;
113
+ const devicesCount = devices.length;
117
114
  if (devicesCount === 0) {
118
115
  devicesList.Info = 'No devices found'
119
116
  return devicesList;
120
117
  }
121
118
 
122
- await this.functions.saveData(this.devicesFile, devicesList.Devices);
123
- if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
124
-
125
119
  devicesList.State = true;
126
120
  devicesList.Info = `Found ${devicesCount} devices`;
121
+ devicesList.Devices = devices;
122
+
123
+ await this.functions.saveData(this.devicesFile, devicesList);
124
+ if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
125
+
127
126
  return devicesList;
128
127
  } catch (error) {
129
128
  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,16 +166,17 @@ 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) {
178
- await connectToMelCloudHome();
179
+ await connect();
179
180
  if (this.logWarn) this.emit('warn', 'Check devices list not possible, cookies expired, trying to get new.');
180
181
  return;
181
182
  }