UNPKG

@elshaer/homebridge-hdl-buspro-enhanced

Version:

Linking the HDL bus into the Homebridge widget

66 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeakSensor = void 0; class LeakSensor { 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.LeakStates = { Detected: this.platform.Characteristic.LeakDetected.LEAK_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.LeakSensor) || this.accessory.addService(Service.LeakSensor); this.service.setCharacteristic(Characteristic.Name, name); this.service.getCharacteristic(Characteristic.LeakDetected) .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.LeakStates.Detected = Characteristic.LeakDetected.LEAK_DETECTED; } else { this.LeakStates.Detected = Characteristic.LeakDetected.LEAK_NOT_DETECTED; } } else { if (contact) { this.LeakStates.Detected = Characteristic.LeakDetected.LEAK_NOT_DETECTED; } else { this.LeakStates.Detected = Characteristic.LeakDetected.LEAK_DETECTED; } } this.service.getCharacteristic(Characteristic.ContactSensorState).updateValue(this.LeakStates.Detected); if (this.LeakStates.Detected === Characteristic.LeakDetected.LEAK_DETECTED) { this.platform.log.debug(this.name + ' has detected leak'); } }); setInterval(() => { this.controller.send({ target: this.device, command: 0x15CE, data: { area: this.area, switch: this.channel }, }, false); }, 1000); } } async getOn() { return this.LeakStates.Detected; } } exports.LeakSensor = LeakSensor; //# sourceMappingURL=LeakSensor.js.map