homebridge-ring
Version:
Homebridge plugin for Ring doorbells, cameras, security alarm system and smart lighting
35 lines (34 loc) • 1.35 kB
JavaScript
import { BaseDeviceAccessory } from "./base-device-accessory.js";
import { hap } from "./hap.js";
export class SmokeCoListener extends BaseDeviceAccessory {
device;
accessory;
config;
constructor(device, accessory, config) {
super();
this.device = device;
this.accessory = accessory;
this.config = config;
const { Characteristic: { SmokeDetected, CarbonMonoxideDetected }, Service: { SmokeSensor, CarbonMonoxideSensor }, } = hap;
this.registerCharacteristic({
characteristicType: SmokeDetected,
serviceType: SmokeSensor,
getValue: (data) => {
return data.smoke && data.smoke.alarmStatus === 'active'
? SmokeDetected.SMOKE_DETECTED
: SmokeDetected.SMOKE_NOT_DETECTED;
},
});
this.registerCharacteristic({
characteristicType: CarbonMonoxideDetected,
serviceType: CarbonMonoxideSensor,
getValue: (data) => {
return data.co && data.co.alarmStatus === 'active'
? CarbonMonoxideDetected.CO_LEVELS_ABNORMAL
: CarbonMonoxideDetected.CO_LEVELS_NORMAL;
},
});
this.initSensorService(SmokeSensor);
this.initSensorService(CarbonMonoxideSensor);
}
}