@elshaer/homebridge-hdl-buspro-enhanced
Version:
Linking the HDL bus into the Homebridge widget
66 lines • 2.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmokeSensor = void 0;
class SmokeSensor {
constructor(platform, accessory, name, controller, device, listener, area, channel, nc) {
this.platform = platform;
this.accessory = accessory;
this.name = name;
this.controller = controller;
this.device = device;
this.listener = listener;
this.area = area;
this.channel = channel;
this.nc = nc;
this.SmokeStates = {
Detected: this.platform.Characteristic.SmokeDetected.SMOKE_NOT_DETECTED,
};
const Service = this.platform.Service;
const Characteristic = this.platform.Characteristic;
this.accessory.getService(Service.AccessoryInformation)
.setCharacteristic(Characteristic.Manufacturer, 'HDL');
this.service =
this.accessory.getService(Service.SmokeSensor) || this.accessory.addService(Service.SmokeSensor);
this.service.setCharacteristic(Characteristic.Name, name);
this.service.getCharacteristic(Characteristic.SmokeDetected)
.onGet(this.getOn.bind(this));
if (area !== -1) {
const eventEmitter = this.listener.getChannelEventEmitter(this.area, this.channel);
eventEmitter.on('update', (contact) => {
if (this.nc) {
if (contact) {
this.SmokeStates.Detected = Characteristic.SmokeDetected.SMOKE_DETECTED;
}
else {
this.SmokeStates.Detected = Characteristic.SmokeDetected.SMOKE_NOT_DETECTED;
}
}
else {
if (contact) {
this.SmokeStates.Detected = Characteristic.SmokeDetected.SMOKE_NOT_DETECTED;
}
else {
this.SmokeStates.Detected = Characteristic.SmokeDetected.SMOKE_DETECTED;
}
}
this.service.getCharacteristic(Characteristic.SmokeDetected).updateValue(this.SmokeStates.Detected);
if (this.SmokeStates.Detected ===
Characteristic.SmokeDetected.SMOKE_DETECTED) {
this.platform.log.debug(this.name + ' has detected smoke');
}
});
setInterval(() => {
this.controller.send({
target: this.device,
command: 0x15CE,
data: { area: this.area, switch: this.channel },
}, false);
}, 1000);
}
}
async getOn() {
return this.SmokeStates.Detected;
}
}
exports.SmokeSensor = SmokeSensor;
//# sourceMappingURL=SmokeSensor.js.map