homebridge-flume 0.5.0 → 0.6.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.6.0 (2021-11-24)
6
+
7
+ ### Added
8
+
9
+ - Leak sensor service
10
+
11
+ ### Changed
12
+
13
+ - Minimum refresh interval increased to two minutes
14
+
5
15
  ## 0.5.0 (2021-11-23)
6
16
 
7
17
  ### Added
@@ -42,8 +42,8 @@
42
42
  "refreshInterval": {
43
43
  "title": "Refresh Interval",
44
44
  "type": "integer",
45
- "placeholder": 1,
46
- "description": "Number of minutes between updates. Must be 1 or more."
45
+ "placeholder": 2,
46
+ "description": "Number of minutes between updates. Must be 2 or more."
47
47
  },
48
48
  "threshold": {
49
49
  "title": "Threshold",
@@ -239,7 +239,37 @@ module.exports = class connectionHTTP {
239
239
 
240
240
  // Log the response if in debug mode
241
241
  if (this.debug) {
242
- this.log('[HTTP getDevice()] %s.', JSON.stringify(res.data))
242
+ this.log('[HTTP getDeviceInfo()] %s.', JSON.stringify(res.data))
243
+ }
244
+
245
+ // Parse the response
246
+ return res.data.data[0]
247
+ }
248
+
249
+ async getLeakInfo (deviceId) {
250
+ // Refresh the access token if it has expired already
251
+ if (Date.now() > this.expiresIn) {
252
+ await this.renewToken()
253
+ }
254
+
255
+ // Send the request
256
+ const res = await axios.get(
257
+ 'https://api.flumetech.com/users/' + this.userId + '/devices/' + deviceId + '/leaks/active',
258
+ {
259
+ headers: {
260
+ Authorization: 'Bearer ' + this.accessToken
261
+ }
262
+ }
263
+ )
264
+
265
+ // Check to see we got a response
266
+ if (!res.data) {
267
+ throw new Error(this.lang.noDataReceived)
268
+ }
269
+
270
+ // Log the response if in debug mode
271
+ if (this.debug) {
272
+ this.log('[HTTP getLeakInfo()] %s.', JSON.stringify(res.data))
243
273
  }
244
274
 
245
275
  // Parse the response
@@ -16,10 +16,26 @@ module.exports = class deviceValve {
16
16
  this.name = accessory.displayName
17
17
  this.platform = platform
18
18
  this.refreshInterval = platform.config.refreshInterval
19
+
20
+ // Add the leak sensor service if it doesn't exist already
21
+ this.leakService =
22
+ this.accessory.getService(this.hapServ.LeakSensor) ||
23
+ this.accessory.addService(this.hapServ.LeakSensor)
24
+
25
+ this.cacheLeak = !!this.leakService.getCharacteristic(this.hapChar.LeakDetected).value
19
26
  }
20
27
 
21
28
  externalUpdate (params) {
22
29
  // Here we deal with the incoming data
30
+ if (
31
+ this.funcs.hasProperty(params.leakInfo, 'active') &&
32
+ params.leakInfo.active !== this.cacheLeak
33
+ ) {
34
+ this.cacheLeak = params.leakInfo.active
35
+ this.leakService.updateCharacteristic(this.hapChar.LeakDetected, this.cacheLeak ? 1 : 0)
36
+ this.log('[%s] current leak status [%sdetected]', this.name, this.cacheLeak ? '' : 'not ')
37
+ }
38
+
23
39
  const usage =
24
40
  params.currentusage && params.currentusage[0] && params.currentusage[0].value
25
41
  ? params.currentusage[0].value
package/lib/index.js CHANGED
@@ -239,9 +239,12 @@ class FlumePlatform {
239
239
  .replace('T', ' ')
240
240
  this.devicesInHB.forEach(async accessory => {
241
241
  try {
242
- const res = await this.httpClient.getDeviceInfo(accessory.context.deviceId, fromWhen)
243
- res.fromWhen = fromWhen
244
- accessory.control.externalUpdate(res)
242
+ const toReturn = { fromWhen }
243
+ const devInfo = await this.httpClient.getDeviceInfo(accessory.context.deviceId, fromWhen)
244
+ toReturn.devInfo = devInfo
245
+ const leakInfo = await this.httpClient.getLeakInfo(accessory.context.deviceId)
246
+ toReturn.leakInfo = leakInfo
247
+ accessory.control.externalUpdate(toReturn)
245
248
  } catch (err) {
246
249
  const eText = this.funcs.parseError(err)
247
250
  this.log.warn('[%s] %s %s.', accessory.displayName, this.lang.devNotRef, eText)
@@ -18,12 +18,12 @@ module.exports = {
18
18
  },
19
19
 
20
20
  defaultValues: {
21
- refreshInterval: 1,
21
+ refreshInterval: 2,
22
22
  threshold: 0
23
23
  },
24
24
 
25
25
  minValues: {
26
- refreshInterval: 1,
26
+ refreshInterval: 2,
27
27
  threshold: 0
28
28
  },
29
29
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-flume",
3
3
  "alias": "Flume",
4
- "version": "0.5.0",
4
+ "version": "0.6.0",
5
5
  "author": {
6
6
  "name": "Ben Potter",
7
7
  "email": "bwp91@icloud.com"