homebridge-flume 0.4.0 → 0.5.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,16 @@
2
2
 
3
3
  All notable changes to homebridge-flume will be documented in this file.
4
4
 
5
+ ## 0.5.0 (2021-11-23)
6
+
7
+ ### Added
8
+
9
+ - Make use of the debug logging option for HTTP responses
10
+
11
+ ### Changed
12
+
13
+ - `client_id` and `client_secret` config options changed to `clientId` and `clientSecret` for consistency
14
+
5
15
  ## 0.4.0 (2021-11-23)
6
16
 
7
17
  ### Added
package/README.md CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  ### Credits
42
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
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
44
  - To the creators/contributors of [Homebridge](https://homebridge.io) who make this plugin possible.
45
45
 
46
46
  ### Disclaimer
@@ -17,39 +17,39 @@
17
17
  "title": "Username",
18
18
  "type": "string",
19
19
  "required": true,
20
- "description": "Your username for accessing the Flume site at https://portal.flumetech.com"
20
+ "description": "Your Flume username."
21
21
  },
22
22
  "password": {
23
23
  "title": "Password",
24
24
  "type": "string",
25
25
  "required": true,
26
- "description": "Your password for accessing the Flume site"
26
+ "description": "Your Flume password."
27
27
  },
28
- "client_id": {
28
+ "clientId": {
29
29
  "title": "Client ID",
30
30
  "type": "string",
31
- "placeholder": "12345678901234567890",
31
+ "placeholder": "1234567890ABCD",
32
32
  "required": true,
33
- "description": "Your Client ID for API access, found in Settings on the Flume site"
33
+ "description": "Your Flume Client ID, found at https://portal.flumetech.com."
34
34
  },
35
- "client_secret": {
35
+ "clientSecret": {
36
36
  "title": "Client Secret",
37
37
  "type": "string",
38
- "placeholder": "1234567890",
38
+ "placeholder": "1234567890ABCDEFGHIJ",
39
39
  "required": true,
40
- "description": "Your Client Secret for API access, found in Settings on the Flume site"
40
+ "description": "Your Flume Client Secret, found at https://portal.flumetech.com."
41
41
  },
42
42
  "refreshInterval": {
43
- "title": "Refresh interval",
43
+ "title": "Refresh Interval",
44
44
  "type": "integer",
45
45
  "placeholder": 1,
46
- "description": "Number of minutes between updates. API has a cap of 120 calls per hour."
46
+ "description": "Number of minutes between updates. Must be 1 or more."
47
47
  },
48
48
  "threshold": {
49
- "title": "Adjustment for False Positives",
49
+ "title": "Threshold",
50
50
  "type": "number",
51
51
  "placeholder": 0,
52
- "description": "Set to ignore a steady water draw below this value (gallons)."
52
+ "description": "Ignore a steady water draw below this value in gallons per refresh interval. Must be 0 or more."
53
53
  },
54
54
  "disableDeviceLogging": {
55
55
  "type": "boolean",
@@ -72,7 +72,7 @@
72
72
  {
73
73
  "type": "fieldset",
74
74
  "title": "Required Settings",
75
- "items": ["username", "password", "client_id", "client_secret"]
75
+ "items": ["username", "password", "clientId", "clientSecret"]
76
76
  },
77
77
  {
78
78
  "type": "fieldset",
@@ -15,8 +15,8 @@ module.exports = class connectionHTTP {
15
15
  this.log = platform.log
16
16
  this.username = platform.config.username
17
17
  this.password = platform.config.password
18
- this.client_id = platform.config.client_id
19
- this.client_secret = platform.config.client_secret
18
+ this.clientId = platform.config.clientId
19
+ this.clientSecret = platform.config.clientSecret
20
20
  }
21
21
 
22
22
  async obtainToken () {
@@ -24,8 +24,8 @@ module.exports = class connectionHTTP {
24
24
  // Generate the JSON data to send
25
25
  const body = {
26
26
  grant_type: 'password',
27
- client_id: this.client_id,
28
- client_secret: this.client_secret,
27
+ client_id: this.clientId,
28
+ client_secret: this.clientSecret,
29
29
  username: this.username,
30
30
  password: this.password
31
31
  }
@@ -62,6 +62,11 @@ module.exports = class connectionHTTP {
62
62
  }
63
63
  */
64
64
 
65
+ // Log the response if in debug mode
66
+ if (this.debug) {
67
+ this.log('[HTTP obtainToken()] %s.', JSON.stringify(res.data))
68
+ }
69
+
65
70
  // Make the token available in other functions
66
71
  this.accessToken = res.data.data[0].access_token
67
72
  this.refreshToken = res.data.data[0].refresh_token
@@ -95,11 +100,16 @@ module.exports = class connectionHTTP {
95
100
 
96
101
  async renewToken () {
97
102
  try {
103
+ // Check we have a refresh token
104
+ if (!this.refreshToken) {
105
+ throw new Error(this.lang.noRefreshToken)
106
+ }
107
+
98
108
  // Generate the JSON data to send
99
109
  const body = {
100
110
  grant_type: 'refresh_token',
101
- client_id: this.client_id,
102
- client_secret: this.client_secret,
111
+ client_id: this.clientId,
112
+ client_secret: this.clientSecret,
103
113
  refresh_token: this.refreshToken
104
114
  }
105
115
  const now = Date.now()
@@ -114,6 +124,11 @@ module.exports = class connectionHTTP {
114
124
  throw new Error(this.lang.noDataReceived)
115
125
  }
116
126
 
127
+ // Log the response if in debug mode
128
+ if (this.debug) {
129
+ this.log('[HTTP renewToken()] %s.', JSON.stringify(res.data))
130
+ }
131
+
117
132
  /*
118
133
  {
119
134
  success: true,
@@ -154,7 +169,7 @@ module.exports = class connectionHTTP {
154
169
  async getDevices () {
155
170
  try {
156
171
  // Check we have a user id
157
- if (!this.userId) {
172
+ if (!this.userId || !this.accessToken) {
158
173
  throw new Error(this.lang.noUserId)
159
174
  }
160
175
 
@@ -169,6 +184,11 @@ module.exports = class connectionHTTP {
169
184
  throw new Error(this.lang.noDataReceived)
170
185
  }
171
186
 
187
+ // Log the response if in debug mode
188
+ if (this.debug) {
189
+ this.log('[HTTP getDevices()] %s.', JSON.stringify(res.data))
190
+ }
191
+
172
192
  return res.data.data
173
193
  } catch (err) {
174
194
  if (err.code && this.consts.httpRetryCodes.includes(err.code)) {
@@ -217,6 +237,11 @@ module.exports = class connectionHTTP {
217
237
  throw new Error(this.lang.noDataReceived)
218
238
  }
219
239
 
240
+ // Log the response if in debug mode
241
+ if (this.debug) {
242
+ this.log('[HTTP getDevice()] %s.', JSON.stringify(res.data))
243
+ }
244
+
220
245
  // Parse the response
221
246
  return res.data.data[0]
222
247
  }
@@ -6,14 +6,13 @@ module.exports = class deviceValve {
6
6
  constructor (platform, accessory) {
7
7
  // Set up variables from the platform
8
8
  this.accessory = accessory
9
- this.disableDeviceLogging = platform.config.disableDeviceLogging
10
9
  this.funcs = platform.funcs
11
10
  this.threshold = platform.config.threshold
12
11
  this.hapChar = platform.api.hap.Characteristic
13
12
  this.hapErr = platform.api.hap.HapStatusError
14
13
  this.hapServ = platform.api.hap.Service
15
14
  this.lang = platform.lang
16
- this.log = platform.log
15
+ this.log = platform.config.disableDeviceLogging ? () => {} : platform.log
17
16
  this.name = accessory.displayName
18
17
  this.platform = platform
19
18
  this.refreshInterval = platform.config.refreshInterval
package/lib/index.js CHANGED
@@ -88,8 +88,8 @@ class FlumePlatform {
88
88
  // Begin applying the user's config
89
89
  for (const [key, val] of Object.entries(config)) {
90
90
  switch (key) {
91
- case 'client_id':
92
- case 'client_secret':
91
+ case 'clientId':
92
+ case 'clientSecret':
93
93
  case 'password':
94
94
  case 'username':
95
95
  if (typeof val !== 'string' || val === '') {
@@ -161,8 +161,8 @@ class FlumePlatform {
161
161
  if (
162
162
  !this.config.username ||
163
163
  !this.config.password ||
164
- !this.config.client_id ||
165
- !this.config.client_secret
164
+ !this.config.clientId ||
165
+ !this.config.clientSecret
166
166
  ) {
167
167
  throw new Error(this.lang.noCreds)
168
168
  }
@@ -7,8 +7,8 @@ module.exports = {
7
7
  name: 'Flume',
8
8
  username: '',
9
9
  password: '',
10
- client_id: '',
11
- client_secret: '',
10
+ clientId: '',
11
+ clientSecret: '',
12
12
  refreshInterval: 1,
13
13
  threshold: 0,
14
14
  disableDeviceLogging: false,
@@ -31,6 +31,7 @@ module.exports = {
31
31
  initialising: 'Initialising plugin',
32
32
  noCreds: 'Flume username and/or password and/or client id/secret not configured',
33
33
  noDataReceived: 'No data received from request',
34
+ noRefreshToken: 'No refresh token has been retrieved',
34
35
  noUserId: 'No user id has been retrieved',
35
36
  pluginNotConf: 'Plugin has not been configured',
36
37
  syncFailed: 'Sync process failed as',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-flume",
3
3
  "alias": "Flume",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "author": {
6
6
  "name": "Ben Potter",
7
7
  "email": "bwp91@icloud.com"