homebridge-melcloud-control 4.2.2-beta.2 → 4.2.2-beta.4

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.2-beta.2",
4
+ "version": "4.2.2-beta.4",
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
@@ -76,22 +76,19 @@ class MelCloud extends EventEmitter {
76
76
  });
77
77
 
78
78
  if (this.logDebug) this.emit('debug', `Scanning for devices...`);
79
-
80
79
  const listDevicesData = await axiosInstance(ApiUrls.ListDevices);
81
80
 
82
81
  if (!listDevicesData || !listDevicesData.data) {
83
- if (this.logWarn) this.emit('warn', `Invalid or empty response from MELCloud API`);
84
- return null;
82
+ devicesList.Info = 'Invalid or empty response from MELCloud API'
83
+ return devicesList;
85
84
  }
86
85
 
87
86
  const buildingsList = listDevicesData.data;
88
-
89
- if (this.logDebug)
90
- this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
87
+ if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
91
88
 
92
89
  if (!Array.isArray(buildingsList) || buildingsList.length === 0) {
93
- if (this.logWarn) this.emit('warn', `No buildings found in MELCloud account`);
94
- return null;
90
+ devicesList.Info = 'No building found'
91
+ return devicesList;
95
92
  }
96
93
 
97
94
  await this.functions.saveData(this.buildingsFile, buildingsList);
@@ -137,8 +134,7 @@ class MelCloud extends EventEmitter {
137
134
  devicesList.Info = `Found ${devicesCount} devices`;
138
135
  return devicesList;
139
136
  } catch (error) {
140
- const msg = error.response ? `HTTP ${error.response.status}: ${error.response.statusText}` : error.message;
141
- throw new Error(`Check devices list error: ${msg}`);
137
+ throw new Error(`Check devices list error: ${error.message}`);
142
138
  }
143
139
  }
144
140
 
@@ -227,7 +223,6 @@ class MelCloud extends EventEmitter {
227
223
  if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
228
224
 
229
225
  if (!buildingsList) {
230
- devicesList.State = false;
231
226
  devicesList.Info = 'No building found'
232
227
  return devicesList;
233
228
  }
@@ -25,11 +25,9 @@ class MelCloudAta extends EventEmitter {
25
25
  this.deviceData = {};
26
26
 
27
27
  //lock flags
28
- this.locks = {
29
- checkState: false,
30
- };
28
+ this.locks = true;
31
29
  this.impulseGenerator = new ImpulseGenerator()
32
- .on('checkState', () => this.handleWithLock('checkState', async () => {
30
+ .on('checkState', () => this.handleWithLock(async () => {
33
31
  await this.checkState();
34
32
  }))
35
33
  .on('state', (state) => {
@@ -37,16 +35,16 @@ class MelCloudAta extends EventEmitter {
37
35
  });
38
36
  }
39
37
 
40
- async handleWithLock(lockKey, fn) {
41
- if (this.locks[lockKey]) return;
38
+ async handleWithLock(fn) {
39
+ if (this.locks) return;
42
40
 
43
- this.locks[lockKey] = true;
41
+ this.locks = true;
44
42
  try {
45
43
  await fn();
46
44
  } catch (error) {
47
45
  this.emit('error', `Inpulse generator error: ${error}`);
48
46
  } finally {
49
- this.locks[lockKey] = false;
47
+ this.locks = false;
50
48
  }
51
49
  }
52
50
 
@@ -282,9 +280,12 @@ class MelCloudAta extends EventEmitter {
282
280
  }
283
281
 
284
282
  updateData(deviceData) {
283
+ this.lock = true;
284
+ this.emit('deviceState', deviceData);
285
+
285
286
  setTimeout(() => {
286
- this.emit('deviceState', deviceData);
287
- }, 300);
287
+ this.lock = false
288
+ }, 1500);
288
289
  }
289
290
 
290
291
  };
@@ -25,11 +25,9 @@ class MelCloudAtw extends EventEmitter {
25
25
  this.devicesData = {};
26
26
 
27
27
  //lock flags
28
- this.locks = {
29
- checkState: false,
30
- };
28
+ this.locks = true;
31
29
  this.impulseGenerator = new ImpulseGenerator()
32
- .on('checkState', () => this.handleWithLock('checkState', async () => {
30
+ .on('checkState', () => this.handleWithLock(async () => {
33
31
  await this.checkState();
34
32
  }))
35
33
  .on('state', (state) => {
@@ -37,16 +35,16 @@ class MelCloudAtw extends EventEmitter {
37
35
  });
38
36
  }
39
37
 
40
- async handleWithLock(lockKey, fn) {
41
- if (this.locks[lockKey]) return;
38
+ async handleWithLock(fn) {
39
+ if (this.locks) return;
42
40
 
43
- this.locks[lockKey] = true;
41
+ this.locks = true;
44
42
  try {
45
43
  await fn();
46
44
  } catch (error) {
47
45
  this.emit('error', `Inpulse generator error: ${error}`);
48
46
  } finally {
49
- this.locks[lockKey] = false;
47
+ this.locks = false;
50
48
  }
51
49
  }
52
50
 
@@ -252,9 +250,12 @@ class MelCloudAtw extends EventEmitter {
252
250
  }
253
251
 
254
252
  updateData(deviceData) {
253
+ this.lock = true;
254
+ this.emit('deviceState', deviceData);
255
+
255
256
  setTimeout(() => {
256
- this.emit('deviceState', deviceData);
257
- }, 300);
257
+ this.lock = false
258
+ }, 1500);
258
259
  }
259
260
  };
260
261
  export default MelCloudAtw;
@@ -25,11 +25,9 @@ class MelCloudErv extends EventEmitter {
25
25
  this.devicesData = {};
26
26
 
27
27
  //lock flags
28
- this.locks = {
29
- checkState: false,
30
- };
28
+ this.locks = true;
31
29
  this.impulseGenerator = new ImpulseGenerator()
32
- .on('checkState', () => this.handleWithLock('checkState', async () => {
30
+ .on('checkState', () => this.handleWithLock(async () => {
33
31
  await this.checkState();
34
32
  }))
35
33
  .on('state', (state) => {
@@ -37,16 +35,16 @@ class MelCloudErv extends EventEmitter {
37
35
  });
38
36
  }
39
37
 
40
- async handleWithLock(lockKey, fn) {
41
- if (this.locks[lockKey]) return;
38
+ async handleWithLock(fn) {
39
+ if (this.locks) return;
42
40
 
43
- this.locks[lockKey] = true;
41
+ this.locks = true;
44
42
  try {
45
43
  await fn();
46
44
  } catch (error) {
47
45
  this.emit('error', `Inpulse generator error: ${error}`);
48
46
  } finally {
49
- this.locks[lockKey] = false;
47
+ this.locks = false;
50
48
  }
51
49
  }
52
50
 
@@ -260,9 +258,12 @@ class MelCloudErv extends EventEmitter {
260
258
  }
261
259
 
262
260
  updateData(deviceData) {
261
+ this.lock = true;
262
+ this.emit('deviceState', deviceData);
263
+
263
264
  setTimeout(() => {
264
- this.emit('deviceState', deviceData);
265
- }, 300);
265
+ this.lock = false
266
+ }, 1500);
266
267
  }
267
268
  };
268
269
  export default MelCloudErv;