-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomeKitHMSmokeDetector.js
36 lines (31 loc) · 1.13 KB
/
HomeKitHMSmokeDetector.js
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
const HomeKit = require('hap-nodejs')
const HomeKitHMDevice = require('./HomeKitHMDevice')
const Service = HomeKit.Service
const Characteristic = HomeKit.Characteristic
class HomeKitHMSmokeDetector extends HomeKitHMDevice {
constructor (accessory, device) {
super(...arguments)
this.applyMappings({
STATE: {
service: Service.SmokeSensor,
characteristic: Characteristic.SmokeDetected,
defaultValue: Characteristic.SmokeDetected.SMOKE_NOT_DETECTED,
valueConversion: value => value ? Characteristic.SmokeDetected.DETECTED
: Characteristic.SmokeDetected.SMOKE_NOT_DETECTED
},
LOWBAT: {
service: Service.SmokeSensor,
characteristic: Characteristic.StatusLowBattery,
defaultValue: Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
}
})
this.hmDevice.on('update', (characteristic, value) => {
if (characteristic === 'UNREACH') {
const sd = this.accessory.getService(Service.SmokeSensor)
sd.getCharacteristic(Characteristic.StatusActive)
.updateValue(!value)
}
})
}
}
module.exports = HomeKitHMSmokeDetector