homebridge-flume 0.3.1 → 0.4.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,12 @@
2
2
 
3
3
  All notable changes to homebridge-flume will be documented in this file.
4
4
 
5
+ ## 0.4.0 (2021-11-23)
6
+
7
+ ### Added
8
+
9
+ - The plugin will remove 'stale' accessories that don't appear in the obtained device list
10
+
5
11
  ## 0.3.1 (2021-11-23)
6
12
 
7
13
  ### Fixed
@@ -18,4 +24,4 @@ Converted from accessory plugin to platform plugin
18
24
 
19
25
  ## 0.1.0 (2021-11-22)
20
26
 
21
- Initial release
27
+ Initial release
@@ -52,20 +52,20 @@
52
52
  "description": "Set to ignore a steady water draw below this value (gallons)."
53
53
  },
54
54
  "disableDeviceLogging": {
55
- "type": "boolean",
56
- "title": "Disable Device Logging",
57
- "description": "Global logging setting for accessory status changes. If true then accessory status changes will not be logged."
58
- },
59
- "debug": {
60
- "title": "Debug Logging",
61
- "type": "boolean",
62
- "description": "Global logging setting for the plugin. If true then debug information will be added to the log."
63
- },
64
- "disablePlugin": {
65
- "title": "Disable Plugin",
66
- "type": "boolean",
67
- "description": "If true, the plugin will remove all accessories and not load the plugin on restart."
68
- }
55
+ "type": "boolean",
56
+ "title": "Disable Device Logging",
57
+ "description": "Global logging setting for accessory status changes. If true then accessory status changes will not be logged."
58
+ },
59
+ "debug": {
60
+ "title": "Debug Logging",
61
+ "type": "boolean",
62
+ "description": "Global logging setting for the plugin. If true then debug information will be added to the log."
63
+ },
64
+ "disablePlugin": {
65
+ "title": "Disable Plugin",
66
+ "type": "boolean",
67
+ "description": "If true, the plugin will remove all accessories and not load the plugin on restart."
68
+ }
69
69
  }
70
70
  },
71
71
  "layout": [
@@ -79,13 +79,7 @@
79
79
  "title": "Optional Settings",
80
80
  "description": "Optional settings for the plugin, including global logging settings.",
81
81
  "expandable": true,
82
- "items": [
83
- "refreshInterval",
84
- "threshold",
85
- "disableDeviceLogging",
86
- "debug",
87
- "disablePlugin"
88
- ]
82
+ "items": ["refreshInterval", "threshold", "disableDeviceLogging", "debug", "disablePlugin"]
89
83
  }
90
84
  ]
91
85
  }
@@ -38,7 +38,7 @@ module.exports = class connectionHTTP {
38
38
 
39
39
  // Check to see we got a response
40
40
  if (!res.data) {
41
- throw new Error(this.lang.noToken)
41
+ throw new Error(this.lang.noDataReceived)
42
42
  }
43
43
 
44
44
  /*
@@ -84,7 +84,7 @@ module.exports = class connectionHTTP {
84
84
  } catch (err) {
85
85
  if (err.code && this.consts.httpRetryCodes.includes(err.code)) {
86
86
  // Retry if another attempt could be successful
87
- this.log.warn('[HTTP login()] %s [%s].', this.lang.httpRetry, err.code)
87
+ this.log.warn('[HTTP obtainToken()] %s [%s].', this.lang.httpRetry, err.code)
88
88
  await this.funcs.sleep(30000)
89
89
  return await this.login()
90
90
  } else {
@@ -111,7 +111,7 @@ module.exports = class connectionHTTP {
111
111
 
112
112
  // Check to see we got a response
113
113
  if (!res.data) {
114
- throw new Error(this.lang.noToken)
114
+ throw new Error(this.lang.noDataReceived)
115
115
  }
116
116
 
117
117
  /*
@@ -142,11 +142,11 @@ module.exports = class connectionHTTP {
142
142
  } catch (err) {
143
143
  if (err.code && this.consts.httpRetryCodes.includes(err.code)) {
144
144
  // Retry if another attempt could be successful
145
- this.log.warn('[HTTP login()] %s [%s].', this.lang.httpRetry, err.code)
145
+ this.log.warn('[HTTP renewToken()] %s [%s].', this.lang.httpRetry, err.code)
146
146
  await this.funcs.sleep(30000)
147
147
  return await this.login()
148
148
  } else {
149
- throw new Error('[HTTP refreshToken()] ' + err.message)
149
+ throw new Error('[HTTP renewToken()] ' + err.message)
150
150
  }
151
151
  }
152
152
  }
@@ -155,7 +155,7 @@ module.exports = class connectionHTTP {
155
155
  try {
156
156
  // Check we have a user id
157
157
  if (!this.userId) {
158
- throw new Error('No user id has been retrieved')
158
+ throw new Error(this.lang.noUserId)
159
159
  }
160
160
 
161
161
  // Perform the HTTP request
@@ -166,14 +166,14 @@ module.exports = class connectionHTTP {
166
166
 
167
167
  // Check to see we got a response
168
168
  if (!res.data) {
169
- throw new Error('No data received')
169
+ throw new Error(this.lang.noDataReceived)
170
170
  }
171
171
 
172
172
  return res.data.data
173
173
  } catch (err) {
174
174
  if (err.code && this.consts.httpRetryCodes.includes(err.code)) {
175
175
  // Retry if another attempt could be successful
176
- this.log.warn('[HTTP login()] %s [%s].', this.lang.httpRetry, err.code)
176
+ this.log.warn('[HTTP getDevices()] %s [%s].', this.lang.httpRetry, err.code)
177
177
  await this.funcs.sleep(30000)
178
178
  return await this.login()
179
179
  } else {
@@ -212,6 +212,11 @@ module.exports = class connectionHTTP {
212
212
  }
213
213
  )
214
214
 
215
+ // Check to see we got a response
216
+ if (!res.data) {
217
+ throw new Error(this.lang.noDataReceived)
218
+ }
219
+
215
220
  // Parse the response
216
221
  return res.data.data[0]
217
222
  }
@@ -27,9 +27,8 @@ module.exports = class deviceValve {
27
27
  : 0
28
28
  if (usage > this.threshold) {
29
29
  this.log(
30
- '[%s] %s - [%s] gallons within the last [%s] minutes.',
30
+ '[%s] usage detected - [%s] gallons within the last [%s] minutes.',
31
31
  this.name,
32
- 'usage detected',
33
32
  usage,
34
33
  this.refreshInterval
35
34
  )
@@ -77,7 +77,11 @@
77
77
  <h4>Credits</h4>
78
78
  <ul>
79
79
  <li>
80
- This is a forked rewrite of the <a href="https://www.npmjs.com/package/homebridge-flume-water-sensor" target="_blank">homebridge-flume-water-sensor</a> plugin by @weallknowwhoisatfaulthere
80
+ This is a forked rewrite of the
81
+ <a href="https://www.npmjs.com/package/homebridge-flume-water-sensor" target="_blank"
82
+ >homebridge-flume-water-sensor</a
83
+ >
84
+ plugin by @weallknowwhoisatfaulthere
81
85
  </li>
82
86
  <li>
83
87
  To the creators/contributors of
package/lib/index.js CHANGED
@@ -174,9 +174,11 @@ class FlumePlatform {
174
174
 
175
175
  // Check we have devices we can work with
176
176
  if (!Array.isArray(deviceList) || deviceList.length === 0) {
177
+ this.devicesInHB.forEach(accessory => this.removeAccessory(accessory))
177
178
  throw new Error(this.lang.noDevices)
178
179
  }
179
180
 
181
+ // Initialise each device into Homebridge
180
182
  deviceList.forEach(device => {
181
183
  if (!device.bridge_id) {
182
184
  return
@@ -184,6 +186,13 @@ class FlumePlatform {
184
186
  this.initialiseDevice(device)
185
187
  })
186
188
 
189
+ // Remove any stale accessories that don't appear in the device list
190
+ this.devicesInHB.forEach(accessory => {
191
+ if (!deviceList.find(el => accessory.context.deviceId === el.id)) {
192
+ this.removeAccessory(accessory)
193
+ }
194
+ })
195
+
187
196
  // Set up an initial last sync time
188
197
  this.lastSync = new Date(Date.now() - this.config.refreshInterval * 60000)
189
198
 
@@ -235,7 +244,7 @@ class FlumePlatform {
235
244
  accessory.control.externalUpdate(res)
236
245
  } catch (err) {
237
246
  const eText = this.funcs.parseError(err)
238
- this.log.warn(eText)
247
+ this.log.warn('[%s] %s %s.', accessory.displayName, this.lang.devNotRef, eText)
239
248
  }
240
249
  })
241
250
 
@@ -4,7 +4,6 @@
4
4
 
5
5
  module.exports = {
6
6
  accNotFound: 'accessory not found',
7
- accNotReady: 'cannot currently be controlled, see plugin startup logs for any error',
8
7
  brand: 'Flume',
9
8
  cfgDef: 'is not a valid number so using default of',
10
9
  cfgDup: 'will be ignored since another entry with this ID already exists',
@@ -15,10 +14,6 @@ module.exports = {
15
14
  cfgRmv: 'is unused and can be removed',
16
15
  cfgQts: 'should not have quotes around its entry',
17
16
  complete: '✓ Setup complete',
18
- curHeat: 'current heating',
19
- curState: 'current state',
20
- curTarg: 'current target',
21
- curTemp: 'current temperature',
22
17
  devAdd: 'has been added to Homebridge',
23
18
  devInit: 'initialised with id',
24
19
  devNotAdd: 'could not be added to Homebridge as',
@@ -29,36 +24,27 @@ module.exports = {
29
24
  devNotUpdated: 'could not be updated as',
30
25
  devRemove: 'has been removed from Homebridge',
31
26
  disabled: 'To change this, set disablePlugin to false',
32
- disableHTTP: 'Disabling HTTP client as',
33
27
  disabling: 'Disabling plugin',
34
28
  hbVersionFail: 'Your version of Homebridge is too low - please update to v1.3',
35
29
  httpRetry: 'Unable to reach Flume, retrying in 30 seconds',
36
30
  initialised: 'Plugin initialised. Setting up accessories...',
37
31
  initialising: 'Initialising plugin',
38
- labelHeating: 'heating',
39
- labelIdle: 'idle',
40
- labelMan: 'manual',
41
- labelSch: 'schedule',
42
- noCreds: 'Flume username and/or password not configured',
43
- noDevices: 'no data received from Flume server whilst obtaining device list',
44
- noTokenExists: 'no Flume account token exists',
32
+ noCreds: 'Flume username and/or password and/or client id/secret not configured',
33
+ noDataReceived: 'No data received from request',
34
+ noUserId: 'No user id has been retrieved',
45
35
  pluginNotConf: 'Plugin has not been configured',
46
- receivingUpdate: 'receiving update',
47
- scheduleFailed: 'Program schedule could not be updated as',
48
- scheduleInvalid: 'Not updating program schedule as configuration is invalid or incomplete',
49
- scheduleUpdated: 'Program schedule successfully updated',
50
36
  syncFailed: 'Sync process failed as',
51
37
  updateFail: 'could not be updated as',
52
38
  zWelcome: [
53
39
  "Don't forget to ☆ this plugin on GitHub if you're finding it useful!",
54
- // 'Have a feature request? Visit https://bit.ly/hb-thermobit-issues to ask!',
40
+ 'Have a feature request? Visit https://bit.ly/hb-flume-issues to ask!',
55
41
  'Interested in sponsoring this plugin? https://github.com/sponsors/bwp91',
56
42
  "Join the plugin's Discord community! https://discord.gg/cMGhNtZ3tW",
57
43
  'Thanks for using this plugin, I hope you find it helpful!',
58
44
  'This plugin has been made with ♥ by bwp91 from the UK!',
59
45
  'Check out my other Homebridge plugins! https://github.com/bwp91',
60
- // 'Have time to give this plugin a review? https://bit.ly/hb-thermobit-review',
61
- // "This plugin needs it's first ☆ rating on HOOBS! https://bit.ly/hb-thermobit-review",
46
+ 'Have time to give this plugin a review? https://bit.ly/hb-flume-review',
47
+ "This plugin needs it's first ☆ rating on HOOBS! https://bit.ly/hb-flume-review",
62
48
  'Want to see this plugin in your own language? Let me know!'
63
49
  ]
64
50
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-flume",
3
3
  "alias": "Flume",
4
- "version": "0.3.1",
4
+ "version": "0.4.0",
5
5
  "author": {
6
6
  "name": "Ben Potter",
7
7
  "email": "bwp91@icloud.com"
@@ -33,6 +33,24 @@
33
33
  "bugs": {
34
34
  "url": "https://github.com/bwp91/homebridge-flume/issues"
35
35
  },
36
+ "funding": [
37
+ {
38
+ "type": "github",
39
+ "url": "https://github.com/sponsors/bwp91"
40
+ },
41
+ {
42
+ "type": "kofi",
43
+ "url": "https://ko-fi.com/bwp91"
44
+ },
45
+ {
46
+ "type": "patreon",
47
+ "url": "https://www.patreon.com/bwp91"
48
+ },
49
+ {
50
+ "type": "paypal",
51
+ "url": "https://www.paypal.me/BenPotter"
52
+ }
53
+ ],
36
54
  "dependencies": {
37
55
  "@homebridge/plugin-ui-utils": "^0.0.19",
38
56
  "axios": "^0.24.0",