mirror of
https://github.com/tsightler/ring-mqtt.git
synced 2025-09-26 21:01:12 +08:00
28 lines
1009 B
JavaScript
28 lines
1009 B
JavaScript
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()
|
|
}
|
|
}
|