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 +10 -0
- package/config.schema.json +2 -2
- package/lib/connection/http.js +31 -1
- package/lib/device/valve.js +16 -0
- package/lib/index.js +6 -3
- package/lib/utils/constants.js +2 -2
- package/package.json +1 -1
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
|
package/config.schema.json
CHANGED
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"refreshInterval": {
|
|
43
43
|
"title": "Refresh Interval",
|
|
44
44
|
"type": "integer",
|
|
45
|
-
"placeholder":
|
|
46
|
-
"description": "Number of minutes between updates. Must be
|
|
45
|
+
"placeholder": 2,
|
|
46
|
+
"description": "Number of minutes between updates. Must be 2 or more."
|
|
47
47
|
},
|
|
48
48
|
"threshold": {
|
|
49
49
|
"title": "Threshold",
|
package/lib/connection/http.js
CHANGED
|
@@ -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
|
|
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
|
package/lib/device/valve.js
CHANGED
|
@@ -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
|
|
243
|
-
|
|
244
|
-
|
|
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)
|
package/lib/utils/constants.js
CHANGED