homebridge-pjlink
Version:
Homebridge accessory for PJLink supported projectors
76 lines • 3.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PJLinkPlatformAccessory = void 0;
const TelevisionHandler_1 = require("./TelevisionHandler");
const InformationHandler_1 = require("./InformationHandler");
const InputSourceHandler_1 = require("./InputSourceHandler");
const TelevisionSpeakerHandler_1 = require("./TelevisionSpeakerHandler");
// import {PJLink} from 'PJLink';
const PJLink = require('pjlink');
class PJLinkPlatformAccessory {
constructor(log, api, config, platform, accessory) {
this.log = log;
this.api = api;
this.config = config;
this.platform = platform;
this.accessory = accessory;
// handle config
const c = config;
this.name = c.name || 'PJLink';
this.manufacturer = c.manufacturer || 'Manufacturer';
this.ip = c.ip;
this.password = c.password || '';
this.port = c.port || 4352;
this.enableSwitch = c.enableSwitch || false;
this.enableSpeaker = c.enableSpeaker || false;
this.log.info('connect', `${this.ip}:${this.port}`);
// pj-link device
this.device = new PJLink(this.ip, this.port, this.password);
// set category
this.accessory.category = 31 /* TELEVISION */;
// handlers
this.tvHandler = new TelevisionHandler_1.TelevisionHandler(this.log, this.api, this.accessory, this.device, this.name, this.enableSwitch);
this.informationHandler = new InformationHandler_1.InformationHandler(this.log, this.api, this.accessory, this.device, config);
this.inputsHandler = new InputSourceHandler_1.InputSourceHandler(this.log, this.api, this.accessory, this.device, config, this.tvHandler.getService());
if (this.enableSpeaker) {
this.speakerHandler = new TelevisionSpeakerHandler_1.TelevisionSpeakerHandler(this.log, this.api, this.accessory, this.device, this.tvHandler.getService(), this.name);
}
if (this.interval) {
this.intervalId = setInterval(this.update.bind(this), this.interval * 1000);
}
this.update();
// console.dir(this.accessory.context);
log.info('finished initializing!');
}
/**
* This method is called directly after creation of this instance.
* It should return all services which should be added to the accessory.
* @returns Service[]
*/
getServices() {
// return this.availableServices;
let services = [
this.informationHandler.getService(),
this.tvHandler.getService(),
];
if (this.speakerHandler) {
services.push(this.speakerHandler.getService());
}
const switchService = this.tvHandler.getSwitchService();
if (switchService) {
services.push(switchService);
}
services = services.concat(this.inputsHandler.getServices());
return services;
}
update() {
// this.informationHandler.update();
this.tvHandler.update();
this.inputsHandler.update();
if (this.speakerHandler) {
this.speakerHandler.update();
}
}
}
exports.PJLinkPlatformAccessory = PJLinkPlatformAccessory;
//# sourceMappingURL=PJLinkPlatformAccessory.js.map