UNPKG

homebridge-pjlink

Version:

Homebridge accessory for PJLink supported projectors

91 lines 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TelevisionSpeakerHandler = void 0; // const PJLink = require('PJLink'); class TelevisionSpeakerHandler { constructor(log, api, accessory, device, tvService, name) { this.log = log; this.api = api; this.accessory = accessory; this.device = device; this.tvService = tvService; this.name = name; this.muted = false; this.speakerService = this.createSpeaker(); } getService() { return this.speakerService; } createSpeaker() { // hap const Service = this.api.hap.Service; const Characteristic = this.api.hap.Characteristic; // service const service = this.accessory.getService(Service.TelevisionSpeaker) || this.accessory.addService(Service.TelevisionSpeaker, this.name, 'tvSpeaker'); service .getCharacteristic(Characteristic.Mute) .on("get" /* GET */, this.getTelevisionMuted.bind(this)) .on("set" /* SET */, this.setTelevisionMuted.bind(this)); this.tvService.addLinkedService(service); return service; } getTelevisionMuted(callback) { try { this.device.getMute((err, state) => { if (err) { this.log.error(err); callback(new Error(err)); } else { this.log.info('muted', state); callback(null, state.audio); } }); } catch (e) { this.log.error(e); callback(e); } } setTelevisionMuted(value, callback) { try { const muted = (value === true); this.device.setMute(muted, (err, resp) => { this.log.info('setMute', muted, err, resp); if (err) { callback(new Error(err)); } else { callback(); } }); } catch (e) { this.log.error(e); callback(e); } } update() { const Characteristic = this.api.hap.Characteristic; try { this.device.getMute((err, state) => { if (err) { this.log.error(err); } else { this.log.info('muted', state); if (state.audio !== this.muted) { this.muted = state.audio; this.speakerService.updateCharacteristic(Characteristic.Mute, this.muted); } } }); } catch (e) { this.log.error(e); } } } exports.TelevisionSpeakerHandler = TelevisionSpeakerHandler; //# sourceMappingURL=TelevisionSpeakerHandler.js.map