homebridge-flume 1.1.0 → 1.2.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 +22 -4
- package/lib/device/leak-sensor.js +13 -0
- package/lib/utils/custom-chars.js +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/connection/http.js
CHANGED
|
@@ -237,8 +237,18 @@ module.exports = class connectionHTTP {
|
|
|
237
237
|
if (Date.now() > this.expiresIn) {
|
|
238
238
|
await this.renewToken()
|
|
239
239
|
}
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
|
|
241
|
+
// Generate dates for the query data
|
|
242
|
+
const date = new Date()
|
|
243
|
+
const startOfToday = date.toISOString().substring(0, 10) + ' 00:00:00'
|
|
244
|
+
|
|
245
|
+
// Set the date to the first of the current month
|
|
246
|
+
date.setDate(1)
|
|
247
|
+
const startOfCurrMonth = date.toISOString().substring(0, 10) + ' 00:00:00'
|
|
248
|
+
|
|
249
|
+
// Set the month to the previous month
|
|
250
|
+
date.setMonth(date.getMonth() - 1)
|
|
251
|
+
const startOfPrevMonth = date.toISOString().substring(0, 10) + ' 00:00:00'
|
|
242
252
|
|
|
243
253
|
// Generate the JSON data to send
|
|
244
254
|
const body = {
|
|
@@ -246,14 +256,22 @@ module.exports = class connectionHTTP {
|
|
|
246
256
|
{
|
|
247
257
|
request_id: 'today',
|
|
248
258
|
bucket: 'DAY',
|
|
249
|
-
since_datetime:
|
|
259
|
+
since_datetime: startOfToday,
|
|
250
260
|
operation: 'SUM',
|
|
251
261
|
units: 'GALLONS'
|
|
252
262
|
},
|
|
253
263
|
{
|
|
254
264
|
request_id: 'month',
|
|
255
265
|
bucket: 'MON',
|
|
256
|
-
since_datetime:
|
|
266
|
+
since_datetime: startOfCurrMonth,
|
|
267
|
+
operation: 'SUM',
|
|
268
|
+
units: 'GALLONS'
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
request_id: 'prevMonth',
|
|
272
|
+
bucket: 'MON',
|
|
273
|
+
since_datetime: startOfPrevMonth,
|
|
274
|
+
until_datetime: startOfCurrMonth,
|
|
257
275
|
operation: 'SUM',
|
|
258
276
|
units: 'GALLONS'
|
|
259
277
|
}
|
|
@@ -33,6 +33,9 @@ module.exports = class deviceLeakSensor {
|
|
|
33
33
|
if (!this.leakService.testCharacteristic(this.cusChar.MonthUsage)) {
|
|
34
34
|
this.leakService.addCharacteristic(this.cusChar.MonthUsage)
|
|
35
35
|
}
|
|
36
|
+
if (!this.leakService.testCharacteristic(this.cusChar.PrevMonthUsage)) {
|
|
37
|
+
this.leakService.addCharacteristic(this.cusChar.PrevMonthUsage)
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
externalUpdate (params) {
|
|
@@ -88,6 +91,16 @@ module.exports = class deviceLeakSensor {
|
|
|
88
91
|
params.waterInfo.month[0].value
|
|
89
92
|
)
|
|
90
93
|
}
|
|
94
|
+
if (
|
|
95
|
+
params.waterInfo.prevMonth &&
|
|
96
|
+
params.waterInfo.prevMonth[0] &&
|
|
97
|
+
this.funcs.hasProperty(params.waterInfo.prevMonth[0], 'value')
|
|
98
|
+
) {
|
|
99
|
+
this.leakService.updateCharacteristic(
|
|
100
|
+
this.cusChar.PrevMonthUsage,
|
|
101
|
+
params.waterInfo.prevMonth[0].value
|
|
102
|
+
)
|
|
103
|
+
}
|
|
91
104
|
}
|
|
92
105
|
}
|
|
93
106
|
}
|
|
@@ -8,7 +8,8 @@ module.exports = class customCharacteristics {
|
|
|
8
8
|
this.hapChar = api.hap.Characteristic
|
|
9
9
|
this.uuids = {
|
|
10
10
|
todayUsage: 'E966F001-079E-48FF-8F27-9C2605A29F52',
|
|
11
|
-
monthUsage: 'E966F002-079E-48FF-8F27-9C2605A29F52'
|
|
11
|
+
monthUsage: 'E966F002-079E-48FF-8F27-9C2605A29F52',
|
|
12
|
+
prevMonthUsage: 'E966F003-079E-48FF-8F27-9C2605A29F52'
|
|
12
13
|
}
|
|
13
14
|
const self = this
|
|
14
15
|
this.TodayUsage = function () {
|
|
@@ -29,10 +30,21 @@ module.exports = class customCharacteristics {
|
|
|
29
30
|
})
|
|
30
31
|
this.value = this.getDefaultValue()
|
|
31
32
|
}
|
|
33
|
+
this.PrevMonthUsage = function () {
|
|
34
|
+
self.hapChar.call(this, 'Previous Month', self.uuids.prevMonthUsage)
|
|
35
|
+
this.setProps({
|
|
36
|
+
format: self.hapChar.Formats.UINT32,
|
|
37
|
+
perms: [self.hapChar.Perms.READ, self.hapChar.Perms.NOTIFY],
|
|
38
|
+
unit: 'Gallons'
|
|
39
|
+
})
|
|
40
|
+
this.value = this.getDefaultValue()
|
|
41
|
+
}
|
|
32
42
|
const inherits = require('util').inherits
|
|
33
43
|
inherits(this.TodayUsage, this.hapChar)
|
|
34
44
|
inherits(this.MonthUsage, this.hapChar)
|
|
45
|
+
inherits(this.PrevMonthUsage, this.hapChar)
|
|
35
46
|
this.TodayUsage.UUID = this.uuids.todayUsage
|
|
36
47
|
this.MonthUsage.UUID = this.uuids.monthUsage
|
|
48
|
+
this.PrevMonthUsage.UUID = this.uuids.prevMonthUsage
|
|
37
49
|
}
|
|
38
50
|
}
|