homebridge-plugin-lares4
Version:
a homebridge plugin to expose Ksenia Lares 4 home automation systems on the Apple ecosystem
30 lines • 1.65 kB
JavaScript
export class Lares4PlatformLightSensor {
platform;
accessory;
service;
constructor(platform, accessory) {
this.platform = platform;
this.accessory = accessory;
this.accessory.getService(this.platform.Service.AccessoryInformation)
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'Ksenia')
.setCharacteristic(this.platform.Characteristic.Model, 'Lares4')
.setCharacteristic(this.platform.Characteristic.SerialNumber, '12345672');
this.service = this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor);
this.service.setCharacteristic(this.platform.Characteristic.Name, `Thermostat ${accessory.context.sensor.details.ID}`);
this.service.getCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel)
.onGet(this.getCurrentAmbientLightLevel.bind(this));
this.platform.lares4?.sensors_status_emitter.subscribe((sensor_status) => {
if (sensor_status.id === this.accessory.context.sensor.id) {
this.setStatus(sensor_status.status);
}
});
}
setStatus(accessoryStatus) {
const lht = accessoryStatus.DOMUS?.LHT ?? 0.1;
this.service.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, Math.max(parseFloat(lht), 0.1));
}
getCurrentAmbientLightLevel() {
return Math.max(parseFloat((this.platform.lares4.status.sensors?.[this.accessory.context.sensor.id].DOMUS).LHT) ?? 0.1, 0.1);
}
}
//# sourceMappingURL=Lares4PlatformLightSensor.js.map