-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBatteryDriver.ts
44 lines (40 loc) · 1.13 KB
/
BatteryDriver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import BoundValueStream from '../../Streams/BoundValueStream'
import ManagedDriver from './ManagedDriver'
import { Value } from 'openzwave-shared'
export default class BatteryDriver extends ManagedDriver {
addValue(index: number, value: Value) {
if (index !== 0) {
return
}
const { Service, Characteristic } = this.hap
const service = this.accessory.getService(Service.BatteryService)
const valueStream = new BoundValueStream(value, this.valueObservables, this.log)
this.registerCharacteristic(index, value, {
service,
valueStream,
characteristic: Characteristic.BatteryLevel,
options: {
transformer: {
zwaveToHomeKit(value) {
return Math.round(Number(value))
},
},
},
})
this.registerCharacteristic(index, value, {
service,
valueStream,
characteristic: Characteristic.StatusLowBattery,
options: {
transformer: {
zwaveToHomeKit(value) {
return Number(value) < 20
? ((Characteristic.StatusLowBattery as any).BATTERY_LEVEL_LOW as number)
: ((Characteristic.StatusLowBattery as any)
.BATTERY_LEVEL_NORMAL as number)
},
},
},
})
}
}