homebridge-flume 2.0.7 → 2.0.9-beta.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  All notable changes to homebridge-flume will be documented in this file.
4
4
 
5
+ ⚠️ Note that Node 14 will no longer be supported after April 2023
6
+
7
+ ## BETA
8
+
9
+ ### Changed
10
+
11
+ - Bump `node` recommended versions to v14.21.1 or v16.18.1 or v18.12.1
12
+
13
+ ## 2.0.8 (2022-10-16)
14
+
15
+ ### Changed
16
+
17
+ - Requests for device info will occur less often, meaning requests for leak info can occur more frequently
18
+ - Minimum refresh interval reduced to 1 minute
19
+ - Bump `node` recommended versions to v14.20.1 or v16.18.0 or v18.11.0
20
+ - Updated `axios` to v1.1.3
21
+
5
22
  ## 2.0.7 (2022-09-25)
6
23
 
7
24
  ### Changed
@@ -58,7 +58,7 @@
58
58
  "title": "Refresh Interval",
59
59
  "type": "integer",
60
60
  "placeholder": 2,
61
- "description": "Number of minutes between updates. Must be 2 or more."
61
+ "description": "Number of minutes between requests to Flume for device leak information. Must be 1 or more."
62
62
  }
63
63
  }
64
64
  },
@@ -7,8 +7,6 @@ export default class {
7
7
  this.cusChar = platform.cusChar;
8
8
  this.hapChar = platform.api.hap.Characteristic;
9
9
  this.hapServ = platform.api.hap.Service;
10
- this.log = platform.config.disableDeviceLogging ? () => {} : platform.log;
11
- this.name = accessory.displayName;
12
10
  this.refreshInterval = platform.config.refreshInterval;
13
11
 
14
12
  // Add the leak sensor service if it doesn't exist already
@@ -33,66 +31,36 @@ export default class {
33
31
 
34
32
  externalUpdate(params) {
35
33
  // Check the data for leak detection
36
- if (
37
- hasProperty(params.leakInfo, 'active')
38
- && params.leakInfo.active !== this.cacheLeak
39
- ) {
34
+ if (hasProperty(params.leakInfo, 'active') && params.leakInfo.active !== this.cacheLeak) {
40
35
  this.cacheLeak = params.leakInfo.active;
41
36
  this.leakService.updateCharacteristic(this.hapChar.LeakDetected, this.cacheLeak ? 1 : 0);
42
- this.log('[%s] current leak status [%sdetected].', this.name, this.cacheLeak ? '' : 'not ');
37
+ this.accessory.log(`current leak status [${this.cacheLeak ? '' : 'not '}detected]`);
43
38
  }
44
39
 
45
40
  // Check the data for battery level, cacheBatt is true for OK and false for LOW
46
- if (
47
- hasProperty(params.devInfo, 'battery_level')
48
- && (params.devInfo.battery_level !== 'low') !== this.cacheBatt
49
- ) {
41
+ if (hasProperty(params.devInfo, 'battery_level') && (params.devInfo.battery_level !== 'low') !== this.cacheBatt) {
50
42
  this.cacheBatt = params.devInfo.battery_level !== 'low';
51
43
  this.leakService.updateCharacteristic(this.hapChar.StatusLowBattery, this.cacheBatt ? 0 : 1);
52
- this.log('[%s] current battery [%s].', this.name, this.cacheBatt ? 'ok' : 'low');
44
+ this.accessory.log(`current battery [${this.cacheBatt ? 'okay' : 'low'}]`);
53
45
  }
54
46
 
55
47
  // Check the data for connectivity, cacheStatus is true for OK and false for NOT CONNECTED
56
- if (
57
- hasProperty(params.devInfo, 'connected')
58
- && params.devInfo.connected !== this.cacheStatus
59
- ) {
48
+ if (hasProperty(params.devInfo, 'connected') && params.devInfo.connected !== this.cacheStatus) {
60
49
  this.cacheStatus = params.devInfo.connected;
61
50
  this.leakService.updateCharacteristic(this.hapChar.StatusFault, this.cacheStatus ? 0 : 1);
62
- this.log('[%s] current status [%sconnected].', this.name, this.cacheStatus ? '' : 'not ');
51
+ this.accessory.log(`current status [${this.cacheStatus ? '' : 'not '}connected]`);
63
52
  }
64
53
 
65
54
  // Water info
66
55
  if (params.waterInfo) {
67
- if (
68
- params.waterInfo.today
69
- && params.waterInfo.today[0]
70
- && hasProperty(params.waterInfo.today[0], 'value')
71
- ) {
72
- this.leakService.updateCharacteristic(
73
- this.cusChar.TodayUsage,
74
- params.waterInfo.today[0].value,
75
- );
56
+ if (params.waterInfo.today && params.waterInfo.today[0] && hasProperty(params.waterInfo.today[0], 'value')) {
57
+ this.leakService.updateCharacteristic(this.cusChar.TodayUsage, params.waterInfo.today[0].value);
76
58
  }
77
- if (
78
- params.waterInfo.month
79
- && params.waterInfo.month[0]
80
- && hasProperty(params.waterInfo.month[0], 'value')
81
- ) {
82
- this.leakService.updateCharacteristic(
83
- this.cusChar.MonthUsage,
84
- params.waterInfo.month[0].value,
85
- );
59
+ if (params.waterInfo.month && params.waterInfo.month[0] && hasProperty(params.waterInfo.month[0], 'value')) {
60
+ this.leakService.updateCharacteristic(this.cusChar.MonthUsage, params.waterInfo.month[0].value);
86
61
  }
87
- if (
88
- params.waterInfo.prevMonth
89
- && params.waterInfo.prevMonth[0]
90
- && hasProperty(params.waterInfo.prevMonth[0], 'value')
91
- ) {
92
- this.leakService.updateCharacteristic(
93
- this.cusChar.PrevMonthUsage,
94
- params.waterInfo.prevMonth[0].value,
95
- );
62
+ if (params.waterInfo.prevMonth && params.waterInfo.prevMonth[0] && hasProperty(params.waterInfo.prevMonth[0], 'value')) {
63
+ this.leakService.updateCharacteristic(this.cusChar.PrevMonthUsage, params.waterInfo.prevMonth[0].value);
96
64
  }
97
65
  }
98
66
  }
package/lib/platform.js CHANGED
@@ -24,7 +24,7 @@ export default class {
24
24
  this.devicesInHB = new Map();
25
25
 
26
26
  // Make sure user is running Homebridge v1.4 or above
27
- if (!api?.versionGreaterOrEqual('1.4.0')) {
27
+ if (!api.versionGreaterOrEqual?.('1.4.0')) {
28
28
  throw new Error(platformLang.hbVersionFail);
29
29
  }
30
30
 
@@ -53,9 +53,11 @@ export default class {
53
53
  this.api.on('shutdown', () => this.pluginShutdown());
54
54
  } catch (err) {
55
55
  // Catch any errors during initialisation
56
- const eText = parseError(err, [platformLang.hbVersionFail, platformLang.pluginNotConf]);
57
56
  log.warn('***** %s. *****', platformLang.disabling);
58
- log.warn('***** %s. *****', eText);
57
+ log.warn('***** %s. *****', parseError(err, [
58
+ platformLang.hbVersionFail,
59
+ platformLang.pluginNotConf,
60
+ ]));
59
61
  }
60
62
  }
61
63
 
@@ -179,6 +181,8 @@ export default class {
179
181
  // Perform a first sync and set up the refresh interval
180
182
  this.counter = 0;
181
183
  this.flumeSync();
184
+
185
+ // Note the Flume API has a limit of 120 requests per hour
182
186
  this.refreshInterval = setInterval(
183
187
  () => this.flumeSync(),
184
188
  this.config.refreshInterval * 60000,
@@ -189,13 +193,12 @@ export default class {
189
193
  this.log('%s. %s', platformLang.complete, platformLang.zWelcome[randIndex]);
190
194
  } catch (err) {
191
195
  // Catch any errors during setup
192
- const eText = parseError(err, [
196
+ this.log.warn('***** %s. *****', platformLang.disabling);
197
+ this.log.warn('***** %s. *****', parseError(err, [
193
198
  platformLang.noCreds,
194
199
  platformLang.noDevices,
195
200
  platformLang.disabled,
196
- ]);
197
- this.log.warn('***** %s. *****', platformLang.disabling);
198
- this.log.warn('***** %s. *****', eText);
201
+ ]));
199
202
  this.pluginShutdown();
200
203
  }
201
204
  }
@@ -220,23 +223,20 @@ export default class {
220
223
  }
221
224
  this.devicesInHB.forEach(async (accessory) => {
222
225
  try {
223
- const toReturn = {};
224
- toReturn.devInfo = await this.httpClient.getDeviceInfo(accessory.context.deviceId);
225
- if (this.counter === 0) {
226
- toReturn.waterInfo = await this.httpClient.getWaterInfo(accessory.context.deviceId);
227
- }
228
- toReturn.leakInfo = await this.httpClient.getLeakInfo(accessory.context.deviceId);
226
+ const toReturn = {
227
+ devInfo: this.counter === 0 ? await this.httpClient.getDeviceInfo(accessory.context.deviceId) : {},
228
+ waterInfo: this.counter === 0 ? await this.httpClient.getWaterInfo(accessory.context.deviceId) : {},
229
+ leakInfo: await this.httpClient.getLeakInfo(accessory.context.deviceId),
230
+ };
229
231
  accessory.control.externalUpdate(toReturn);
230
232
  } catch (err) {
231
- const eText = parseError(err);
232
- this.log.warn('[%s] %s %s.', accessory.displayName, platformLang.devNotRef, eText);
233
+ this.log.warn('[%s] %s %s.', accessory.displayName, platformLang.devNotRef, parseError(err));
233
234
  }
234
235
  this.counter += 1;
235
236
  });
236
237
  } catch (err) {
237
238
  // Catch any errors performing the sync
238
- const eText = parseError(err, []);
239
- this.log.warn('%s %s.', platformLang.syncFailed, eText);
239
+ this.log.warn('%s %s.', platformLang.syncFailed, parseError(err));
240
240
  }
241
241
  }
242
242
 
@@ -269,13 +269,15 @@ export default class {
269
269
 
270
270
  // Create the instance for this device type
271
271
  accessory.control = new deviceLeakSensor(this, accessory);
272
+ accessory.log = (msg) => this.log('[%s] %s.', accessory.displayName, msg);
272
273
 
273
274
  // Log the device initialisation
274
275
  this.log('[%s] %s [%s].', accessory.displayName, platformLang.devInit, device.id);
275
276
  } catch (err) {
276
277
  // Catch any errors during device initialisation
277
- const eText = parseError(err, [platformLang.accNotFound]);
278
- this.log.warn('[%s] %s %s.', device.id, platformLang.devNotInit, eText);
278
+ this.log.warn('[%s] %s %s.', device.id, platformLang.devNotInit, parseError(err, [
279
+ platformLang.accNotFound,
280
+ ]));
279
281
  }
280
282
  }
281
283
 
@@ -299,8 +301,7 @@ export default class {
299
301
  return accessory;
300
302
  } catch (err) {
301
303
  // Catch any errors during add
302
- const eText = parseError(err);
303
- this.log.warn('[%s] %s %s.', platformLang.brand, platformLang.devNotAdd, eText);
304
+ this.log.warn('[%s] %s %s.', platformLang.brand, platformLang.devNotAdd, parseError(err));
304
305
  return false;
305
306
  }
306
307
  }
@@ -318,9 +319,7 @@ export default class {
318
319
  this.log('[%s] %s.', accessory.displayName, platformLang.devRemove);
319
320
  } catch (err) {
320
321
  // Catch any errors during remove
321
- const eText = parseError(err);
322
- const name = accessory.displayName;
323
- this.log.warn('[%s] %s %s.', name, platformLang.devNotRemove, eText);
322
+ this.log.warn('[%s] %s %s.', accessory.displayName, platformLang.devNotRemove, parseError(err));
324
323
  }
325
324
  }
326
325
  }
@@ -17,7 +17,7 @@ export default {
17
17
  },
18
18
 
19
19
  minValues: {
20
- refreshInterval: 2,
20
+ refreshInterval: 1,
21
21
  },
22
22
 
23
23
  httpRetryCodes: ['ENOTFOUND', 'ETIMEDOUT', 'EAI_AGAIN', 'ECONNABORTED'],
@@ -21,7 +21,7 @@ export default {
21
21
  devRemove: 'has been removed from Homebridge',
22
22
  disabled: 'To change this, set disablePlugin to false',
23
23
  disabling: 'Disabling plugin',
24
- hbVersionFail: 'Your version of Homebridge is too low - please update to v1.3',
24
+ hbVersionFail: 'Your version of Homebridge is too low - please update to v1.5',
25
25
  httpRetry: 'Unable to reach Flume, retrying in 30 seconds',
26
26
  initialised: 'Plugin initialised. Setting up accessories...',
27
27
  initialising: 'Initialising plugin',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-flume",
3
3
  "alias": "Flume",
4
- "version": "2.0.7",
4
+ "version": "2.0.9-beta.0",
5
5
  "author": {
6
6
  "name": "Ben Potter",
7
7
  "email": "bwp91@icloud.com"
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "engines": {
31
31
  "homebridge": "^1.5.0",
32
- "node": "^14.20.1 || ^16.17.1"
32
+ "node": "^14.21.1 || ^16.18.1 || ^18.12.1"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
@@ -58,7 +58,7 @@
58
58
  ],
59
59
  "dependencies": {
60
60
  "@homebridge/plugin-ui-utils": "^0.0.19",
61
- "axios": "^0.27.2",
61
+ "axios": "^1.1.3",
62
62
  "jwt-decode": "^3.1.2"
63
63
  },
64
64
  "devDependencies": {
@@ -66,6 +66,6 @@
66
66
  "eslint-plugin-import": "^2.26.0",
67
67
  "eslint-plugin-import-newlines": "^1.2.3",
68
68
  "eslint-plugin-sort-exports": "^0.7.0",
69
- "eslint": "^8.24.0"
69
+ "eslint": "^8.27.0"
70
70
  }
71
71
  }