homebridge-flume 0.6.0 → 0.7.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 +6 -0
- package/lib/connection/http.js +32 -2
- package/lib/device/valve.js +28 -4
- package/lib/index.js +5 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/connection/http.js
CHANGED
|
@@ -202,7 +202,37 @@ module.exports = class connectionHTTP {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
async getDeviceInfo (deviceId
|
|
205
|
+
async getDeviceInfo (deviceId) {
|
|
206
|
+
// Refresh the access token if it has expired already
|
|
207
|
+
if (Date.now() > this.expiresIn) {
|
|
208
|
+
await this.renewToken()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Send the request
|
|
212
|
+
const res = await axios.get(
|
|
213
|
+
'https://api.flumetech.com/users/' + this.userId + '/devices/' + deviceId,
|
|
214
|
+
{
|
|
215
|
+
headers: {
|
|
216
|
+
Authorization: 'Bearer ' + this.accessToken
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
// Check to see we got a response
|
|
222
|
+
if (!res.data) {
|
|
223
|
+
throw new Error(this.lang.noDataReceived)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Log the response if in debug mode
|
|
227
|
+
if (this.debug) {
|
|
228
|
+
this.log('[HTTP getDeviceInfo()] %s.', JSON.stringify(res.data))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Parse the response
|
|
232
|
+
return res.data.data[0]
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async getWaterInfo (deviceId, fromWhen) {
|
|
206
236
|
// Refresh the access token if it has expired already
|
|
207
237
|
if (Date.now() > this.expiresIn) {
|
|
208
238
|
await this.renewToken()
|
|
@@ -239,7 +269,7 @@ module.exports = class connectionHTTP {
|
|
|
239
269
|
|
|
240
270
|
// Log the response if in debug mode
|
|
241
271
|
if (this.debug) {
|
|
242
|
-
this.log('[HTTP
|
|
272
|
+
this.log('[HTTP getWaterInfo()] %s.', JSON.stringify(res.data))
|
|
243
273
|
}
|
|
244
274
|
|
|
245
275
|
// Parse the response
|
package/lib/device/valve.js
CHANGED
|
@@ -23,22 +23,46 @@ module.exports = class deviceValve {
|
|
|
23
23
|
this.accessory.addService(this.hapServ.LeakSensor)
|
|
24
24
|
|
|
25
25
|
this.cacheLeak = !!this.leakService.getCharacteristic(this.hapChar.LeakDetected).value
|
|
26
|
+
this.cacheBatt = !this.leakService.getCharacteristic(this.hapChar.StatusLowBattery).value
|
|
27
|
+
this.cacheStatus = !this.leakService.getCharacteristic(this.hapChar.StatusFault).value
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
externalUpdate (params) {
|
|
29
|
-
//
|
|
31
|
+
// Check the data for leak detection
|
|
30
32
|
if (
|
|
31
33
|
this.funcs.hasProperty(params.leakInfo, 'active') &&
|
|
32
34
|
params.leakInfo.active !== this.cacheLeak
|
|
33
35
|
) {
|
|
34
36
|
this.cacheLeak = params.leakInfo.active
|
|
35
37
|
this.leakService.updateCharacteristic(this.hapChar.LeakDetected, this.cacheLeak ? 1 : 0)
|
|
36
|
-
this.log('[%s] current leak status [%sdetected]', this.name, this.cacheLeak ? '' : 'not ')
|
|
38
|
+
this.log('[%s] current leak status [%sdetected].', this.name, this.cacheLeak ? '' : 'not ')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Check the data for battery level, cacheBatt is true for OK and false for LOW
|
|
42
|
+
if (
|
|
43
|
+
this.funcs.hasProperty(params.devInfo, 'battery_level') &&
|
|
44
|
+
(params.devInfo.battery_level !== 'low') !== this.cacheBatt
|
|
45
|
+
) {
|
|
46
|
+
this.cacheBatt = params.devInfo.battery_level !== 'low'
|
|
47
|
+
this.leakService.updateCharacteristic(this.hapChar.StatusLowBattery, this.cacheBatt ? 0 : 1)
|
|
48
|
+
this.log('[%s] current battery [%s].', this.name, this.cacheBatt ? 'ok' : 'low')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Check the data for connectivity, cacheStatus is true for OK and false for NOT CONNECTED
|
|
52
|
+
if (
|
|
53
|
+
this.funcs.hasProperty(params.devInfo, 'connected') &&
|
|
54
|
+
params.devInfo.connected !== this.cacheStatus
|
|
55
|
+
) {
|
|
56
|
+
this.cacheStatus = params.devInfo.connected
|
|
57
|
+
this.leakService.updateCharacteristic(this.hapChar.StatusFault, this.cacheStatus ? 0 : 1)
|
|
58
|
+
this.log('[%s] current status [%sconnected].', this.name, this.cacheStatus ? '' : 'not ')
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
const usage =
|
|
40
|
-
params.
|
|
41
|
-
|
|
62
|
+
params.waterInfo.currentusage &&
|
|
63
|
+
params.waterInfo.currentusage[0] &&
|
|
64
|
+
params.waterInfo.currentusage[0].value
|
|
65
|
+
? params.waterInfo.currentusage[0].value
|
|
42
66
|
: 0
|
|
43
67
|
if (usage > this.threshold) {
|
|
44
68
|
this.log(
|
package/lib/index.js
CHANGED
|
@@ -233,15 +233,17 @@ class FlumePlatform {
|
|
|
233
233
|
|
|
234
234
|
async flumeSync () {
|
|
235
235
|
try {
|
|
236
|
-
const
|
|
236
|
+
const since = this.lastSync
|
|
237
237
|
.toISOString()
|
|
238
238
|
.substring(0, 19)
|
|
239
239
|
.replace('T', ' ')
|
|
240
240
|
this.devicesInHB.forEach(async accessory => {
|
|
241
241
|
try {
|
|
242
|
-
const toReturn = {
|
|
243
|
-
const devInfo = await this.httpClient.getDeviceInfo(accessory.context.deviceId
|
|
242
|
+
const toReturn = { since }
|
|
243
|
+
const devInfo = await this.httpClient.getDeviceInfo(accessory.context.deviceId)
|
|
244
244
|
toReturn.devInfo = devInfo
|
|
245
|
+
const waterInfo = await this.httpClient.getWaterInfo(accessory.context.deviceId, since)
|
|
246
|
+
toReturn.waterInfo = waterInfo
|
|
245
247
|
const leakInfo = await this.httpClient.getLeakInfo(accessory.context.deviceId)
|
|
246
248
|
toReturn.leakInfo = leakInfo
|
|
247
249
|
accessory.control.externalUpdate(toReturn)
|