@elshaer/homebridge-hdl-buspro-enhanced
Version:
Linking the HDL bus into the Homebridge widget
81 lines • 3.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SensorListener = exports.Sensor8in1 = void 0;
class Sensor8in1 {
constructor(platform, accessory, name, controller, device, listener) {
this.platform = platform;
this.accessory = accessory;
this.name = name;
this.controller = controller;
this.device = device;
this.listener = listener;
this.SensorStates = {
Temperature: 0,
Brightness: 0.0001,
Motion: false,
Sound: false,
};
const Service = this.platform.Service;
const Characteristic = this.platform.Characteristic;
this.accessory.getService(Service.AccessoryInformation)
.setCharacteristic(Characteristic.Manufacturer, 'HDL');
this.temp_service = this.accessory.getService(Service.TemperatureSensor) ||
this.accessory.addService(Service.TemperatureSensor);
this.temp_service.getCharacteristic(Characteristic.CurrentTemperature)
.onGet(this.handleCurrentTemperatureGet.bind(this));
this.brightness_service = this.accessory.getService(Service.LightSensor) ||
this.accessory.addService(Service.LightSensor);
this.brightness_service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.onGet(this.handleCurrentAmbientLightLevelGet.bind(this));
this.motion_service = this.accessory.getService(Service.MotionSensor) ||
this.accessory.addService(Service.MotionSensor);
this.motion_service.getCharacteristic(Characteristic.MotionDetected)
.onGet(this.handleMotionDetectedGet.bind(this));
this.sound_service = this.accessory.getService(Service.Microphone) ||
this.accessory.addService(Service.Microphone);
this.sound_service.getCharacteristic(Characteristic.Mute)
.onGet(this.handleMuteGet.bind(this));
this.device.on(0x1646, (command) => {
const data = command.data;
this.SensorStates.Temperature = data.temperature;
this.temp_service.getCharacteristic(Characteristic.CurrentTemperature).updateValue(this.SensorStates.Temperature);
//this.platform.log.debug(this.name + ' updated temperature is ', this.SensorStates.Temperature);
this.SensorStates.Brightness = data.brightness + 0.0001;
this.brightness_service.getCharacteristic(Characteristic.CurrentAmbientLightLevel).updateValue(this.SensorStates.Brightness);
//this.platform.log.debug(this.name + ' updated brightness is ', this.SensorStates.Brightness);
this.SensorStates.Motion = data.movement;
this.motion_service.getCharacteristic(Characteristic.MotionDetected).updateValue(this.SensorStates.Motion);
//this.platform.log.debug(this.name + ' motion status = ', this.SensorStates.Motion);
this.SensorStates.Sound = !data.sonic;
this.sound_service.getCharacteristic(Characteristic.Mute).updateValue(this.SensorStates.Sound);
//this.platform.log.debug(this.name + ' mute status = ', this.SensorStates.Sound);
});
setInterval(() => {
this.controller.send({
target: this.device,
command: 0x1645,
}, false);
}, 1000);
}
async handleCurrentTemperatureGet() {
return this.SensorStates.Temperature;
}
async handleCurrentAmbientLightLevelGet() {
return this.SensorStates.Brightness;
}
async handleMotionDetectedGet() {
return this.SensorStates.Motion;
}
async handleMuteGet() {
return this.SensorStates.Sound;
}
}
exports.Sensor8in1 = Sensor8in1;
class SensorListener {
constructor(device, controller) {
this.device = device;
this.controller = controller;
}
}
exports.SensorListener = SensorListener;
//# sourceMappingURL=Sensor8in1.js.map