homebridge-flume 0.2.0 → 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,10 +2,26 @@
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
+
11
+ ## 0.3.1 (2021-11-23)
12
+
13
+ ### Fixed
14
+
15
+ - Some logging references to Thermobit rather than Flume
16
+
17
+ ## 0.3.0 (2021-11-22)
18
+
19
+ Changed some configuration options
20
+
5
21
  ## 0.2.0 (2021-11-22)
6
22
 
7
23
  Converted from accessory plugin to platform plugin
8
24
 
9
25
  ## 0.1.0 (2021-11-22)
10
26
 
11
- Initial release
27
+ Initial release
package/README.md CHANGED
@@ -1,32 +1,49 @@
1
- # homebridge-flume
2
-
3
- # Configuration
4
-
5
- Configuration sample:
6
-
7
- ```
8
- {
9
- "name": "Flume Water Monitor",
10
- "username": "user@domain.com",
11
- "password": "password",
12
- "client_id": "12345678901234567890",
13
- "client_secret": "1234567890",
14
- "polling_minutes": 1,
15
- "handicap": 0.1,
16
- "platform": "Flume"
17
- }
18
- ```
19
-
20
- Fields:
21
-
22
- - "username": Your username for accessing the Flume site at https://portal.flumetech.com/ (required)
23
- - "password": Your password for accessing the Flume site (required)
24
- - "client_id": Your Client ID for API access, found in Settings on the Flume site (required)
25
- - "client_secret": Your Client Secret for API access, found in Settings on the Flume site (required)
26
- - "polling_minutes": Number of minutes between updates. Defaults to 1 minute. API has a cap of 120 calls per hour. (optional)
27
- - "handicap": Set to ignore a steady water draw below this value. Defaults to zero (0.0) gallons. (optional)
28
-
29
- # Retrieving API Login Credentials
30
-
31
- You'll need to get your API Access Client ID and Client Secret from Flume's site at https://portal.flumetech.com/
32
- This guide offers the steps to take: https://flumetech.readme.io/reference#accessing-the-api
1
+ <span align="center">
2
+
3
+ # homebridge-flume
4
+
5
+ Homebridge plugin to integrate Flume devices into HomeKit
6
+
7
+ [![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
8
+ [![npm](https://img.shields.io/npm/v/homebridge-flume/latest?label=latest)](https://www.npmjs.com/package/homebridge-flume)
9
+ [![npm](https://img.shields.io/npm/v/homebridge-flume/beta?label=beta)](https://github.com/bwp91/homebridge-flume/wiki/Beta-Version)
10
+ [![npm](https://img.shields.io/npm/dt/homebridge-flume)](https://www.npmjs.com/package/homebridge-flume)
11
+ [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
12
+ [![Discord](https://img.shields.io/discord/784827113378676736?color=728ED5&logo=discord&label=bwp91-discord)](https://discord.com/channels/784827113378676736/784827113378676739)
13
+ [![Discord](https://img.shields.io/discord/432663330281226270?color=728ED5&logo=discord&label=hb-discord)](https://discord.com/channels/432663330281226270/742733745743855627)
14
+
15
+ </span>
16
+
17
+ ### Plugin Information
18
+
19
+ - This plugin allows you to view and control your Flume devices within HomeKit.
20
+
21
+ ### Prerequisites
22
+
23
+ - To use this plugin, you will need to already have [Homebridge](https://homebridge.io) (at least v1.3) or [HOOBS](https://hoobs.org) (at least v4.1) installed. Refer to the links for more information and installation instructions.
24
+ - Whilst it is recommended to use [Node](https://nodejs.org/en/) v16, the plugin supports v12 and v14 as per the [Homebridge guidelines](https://github.com/homebridge/homebridge/wiki/How-To-Update-Node.js).
25
+
26
+ ### Setup
27
+
28
+ - [Installation](https://github.com/bwp91/homebridge-flume/wiki/Installation)
29
+ - [Configuration](https://github.com/bwp91/homebridge-flume/wiki/Configuration)
30
+ - [Beta Version](https://github.com/bwp91/homebridge-flume/wiki/Beta-Version)
31
+ - [Node Version](https://github.com/bwp91/homebridge-flume/wiki/Node-Version)
32
+ - [Uninstallation](https://github.com/bwp91/homebridge-flume/wiki/Uninstallation)
33
+
34
+ ### Help/About
35
+
36
+ - [Common Errors](https://github.com/bwp91/homebridge-flume/wiki/Common-Errors)
37
+ - [Support Request](https://github.com/bwp91/homebridge-flume/issues/new/choose)
38
+ - [Changelog](https://github.com/bwp91/homebridge-flume/blob/latest/CHANGELOG.md)
39
+ - [About Me](https://github.com/sponsors/bwp91)
40
+
41
+ ### Credits
42
+
43
+ - This is a forked rewrite of the [homebridge-flume-water-sensor](https://www.npmjs.com/package/homebridge-flume-water-sensor) plugin by @weallknowwhoisatfaulthere
44
+ - To the creators/contributors of [Homebridge](https://homebridge.io) who make this plugin possible.
45
+
46
+ ### Disclaimer
47
+
48
+ - I am in no way affiliated with Flume and this plugin is a personal project that I maintain in my free time.
49
+ - Use this plugin entirely at your own risk - please see licence for more information.
@@ -39,18 +39,47 @@
39
39
  "required": true,
40
40
  "description": "Your Client Secret for API access, found in Settings on the Flume site"
41
41
  },
42
- "polling_minutes": {
43
- "title": "Update Interval",
42
+ "refreshInterval": {
43
+ "title": "Refresh interval",
44
44
  "type": "integer",
45
45
  "placeholder": 1,
46
46
  "description": "Number of minutes between updates. API has a cap of 120 calls per hour."
47
47
  },
48
- "handicap": {
48
+ "threshold": {
49
49
  "title": "Adjustment for False Positives",
50
50
  "type": "number",
51
51
  "placeholder": 0,
52
52
  "description": "Set to ignore a steady water draw below this value (gallons)."
53
+ },
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."
53
68
  }
54
69
  }
55
- }
70
+ },
71
+ "layout": [
72
+ {
73
+ "type": "fieldset",
74
+ "title": "Required Settings",
75
+ "items": ["username", "password", "client_id", "client_secret"]
76
+ },
77
+ {
78
+ "type": "fieldset",
79
+ "title": "Optional Settings",
80
+ "description": "Optional settings for the plugin, including global logging settings.",
81
+ "expandable": true,
82
+ "items": ["refreshInterval", "threshold", "disableDeviceLogging", "debug", "disablePlugin"]
83
+ }
84
+ ]
56
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
  }
@@ -8,7 +8,7 @@ module.exports = class deviceValve {
8
8
  this.accessory = accessory
9
9
  this.disableDeviceLogging = platform.config.disableDeviceLogging
10
10
  this.funcs = platform.funcs
11
- this.handicap = platform.config.handicap
11
+ this.threshold = platform.config.threshold
12
12
  this.hapChar = platform.api.hap.Characteristic
13
13
  this.hapErr = platform.api.hap.HapStatusError
14
14
  this.hapServ = platform.api.hap.Service
@@ -16,7 +16,7 @@ module.exports = class deviceValve {
16
16
  this.log = platform.log
17
17
  this.name = accessory.displayName
18
18
  this.platform = platform
19
- this.polling_minutes = platform.config.polling_minutes
19
+ this.refreshInterval = platform.config.refreshInterval
20
20
  }
21
21
 
22
22
  externalUpdate (params) {
@@ -25,13 +25,12 @@ module.exports = class deviceValve {
25
25
  params.currentusage && params.currentusage[0] && params.currentusage[0].value
26
26
  ? params.currentusage[0].value
27
27
  : 0
28
- if (usage > this.handicap) {
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
- this.polling_minutes
33
+ this.refreshInterval
35
34
  )
36
35
  }
37
36
  }
@@ -76,6 +76,13 @@
76
76
  </ul>
77
77
  <h4>Credits</h4>
78
78
  <ul>
79
+ <li>
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
85
+ </li>
79
86
  <li>
80
87
  To the creators/contributors of
81
88
  <a href="https://homebridge.io" target="_blank">Homebridge</a> who make this plugin possible.
package/lib/index.js CHANGED
@@ -106,7 +106,7 @@ class FlumePlatform {
106
106
  }
107
107
  this.config[key] = val === 'false' ? false : !!val
108
108
  break
109
- case 'handicap': {
109
+ case 'threshold': {
110
110
  if (typeof v === 'string') {
111
111
  logQuotes(key)
112
112
  }
@@ -122,7 +122,7 @@ class FlumePlatform {
122
122
  case 'platform':
123
123
  case 'plugin_map':
124
124
  break
125
- case 'polling_minutes': {
125
+ case 'refreshInterval': {
126
126
  if (typeof val === 'string') {
127
127
  logQuotes(key)
128
128
  }
@@ -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,14 +186,21 @@ 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
- this.lastSync = new Date(Date.now() - this.config.polling_minutes * 60000)
197
+ this.lastSync = new Date(Date.now() - this.config.refreshInterval * 60000)
189
198
 
190
199
  // Perform a first sync and setup the refresh interval
191
200
  this.flumeSync()
192
201
  this.refreshInterval = setInterval(
193
202
  () => this.flumeSync(),
194
- this.config.polling_minutes * 60000
203
+ this.config.refreshInterval * 60000
195
204
  )
196
205
 
197
206
  // Log that the plugin setup has been successful with a welcome message
@@ -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
 
@@ -9,8 +9,8 @@ module.exports = {
9
9
  password: '',
10
10
  client_id: '',
11
11
  client_secret: '',
12
- polling_minutes: 1,
13
- handicap: 0,
12
+ refreshInterval: 1,
13
+ threshold: 0,
14
14
  disableDeviceLogging: false,
15
15
  debug: false,
16
16
  disablePlugin: false,
@@ -18,13 +18,13 @@ module.exports = {
18
18
  },
19
19
 
20
20
  defaultValues: {
21
- polling_minutes: 1,
22
- handicap: 0
21
+ refreshInterval: 1,
22
+ threshold: 0
23
23
  },
24
24
 
25
25
  minValues: {
26
- polling_minutes: 1,
27
- handicap: 0
26
+ refreshInterval: 1,
27
+ threshold: 0
28
28
  },
29
29
 
30
30
  httpRetryCodes: ['ENOTFOUND', 'ETIMEDOUT', 'EAI_AGAIN', 'ECONNABORTED']
@@ -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
- httpRetry: 'Unable to reach Thermobit, retrying in 30 seconds',
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: 'Thermobit username and/or password not configured',
43
- noDevices: 'no data received from Thermobit server whilst obtaining device list',
44
- noTokenExists: 'no Thermobit 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.2.0",
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",