homebridge-pjlink
Version:
Homebridge accessory for PJLink supported projectors
67 lines • 2.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InformationHandler = void 0;
// const PJLink = require('PJLink');
class InformationHandler {
constructor(log, api, accessory, device, config) {
this.log = log;
this.api = api;
this.accessory = accessory;
this.device = device;
// config
this.manufacturer = config.manufacturer || 'Manufacturer';
this.model = config.model || 'Model';
this.serialNumber = config.serialNumber || 'Serial';
this.version = config.version || 'Version';
this.informationService = this.createService();
}
createService() {
// hap
const Service = this.api.hap.Service;
const Characteristic = this.api.hap.Characteristic;
const service = (this.accessory.getService(Service.AccessoryInformation) ||
this.accessory.addService(Service.AccessoryInformation));
service
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
.setCharacteristic(Characteristic.Model, this.model)
.setCharacteristic(Characteristic.SerialNumber, this.serialNumber)
.setCharacteristic(Characteristic.FirmwareRevision, this.version);
this.update();
return service;
}
getService() {
return this.informationService;
}
update() {
// hap
const Characteristic = this.api.hap.Characteristic;
try {
this.device.getManufacturer((error, manufacturer) => {
this.log.info('getManufacturer', error, manufacturer);
if (!error && manufacturer) {
this.manufacturer = manufacturer;
this.informationService.updateCharacteristic(Characteristic.Manufacturer, this.manufacturer);
}
});
this.device.getModel((error, model) => {
this.log.info('getModel', error, model);
if (!error && model) {
this.model = model;
this.informationService.updateCharacteristic(Characteristic.Model, this.model);
}
});
this.device.getInfo((error, info) => {
this.log.info('info', error, info);
if (!error && info) {
this.version = info;
this.informationService.updateCharacteristic(Characteristic.FirmwareRevision, this.version);
}
});
}
catch (e) {
this.log.error(e);
}
}
}
exports.InformationHandler = InformationHandler;
//# sourceMappingURL=InformationHandler.js.map