-
Notifications
You must be signed in to change notification settings - Fork 106
/
smoke-co-listener.js
27 lines (24 loc) · 1009 Bytes
/
smoke-co-listener.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
import RingSocketDevice from './base-socket-device.js'
export default class SmokeCoListener extends RingSocketDevice {
constructor(deviceInfo) {
super(deviceInfo, 'alarm')
this.deviceData.mdl = 'Smoke & CO Listener'
this.entity.smoke = {
component: 'binary_sensor',
device_class: 'smoke'
}
this.entity.co = {
component: 'binary_sensor',
device_class: 'gas',
name: `CO`,
unique_id: `${this.deviceId}_gas` // Force backward compatible unique ID for this entity
}
}
publishState() {
const smokeState = this.device.data.smoke && this.device.data.smoke.alarmStatus === 'active' ? 'ON' : 'OFF'
const coState = this.device.data.co && this.device.data.co.alarmStatus === 'active' ? 'ON' : 'OFF'
this.mqttPublish(this.entity.smoke.state_topic, smokeState)
this.mqttPublish(this.entity.co.state_topic, coState)
this.publishAttributes()
}
}