UNPKG

@dskowronski/homebridge-denon-marantz-avr

Version:

Denon and Marantz AVR support for Homebridge: https://github.com/nfarina/homebridge

60 lines 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DenonMarantzAVRPlatform = void 0; const accessory_1 = require("./accessory"); const controller_1 = require("./controller"); const settings_1 = require("./settings"); class DenonMarantzAVRPlatform { constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.Service = this.api.hap.Service; this.Characteristic = this.api.hap.Characteristic; this.platformAccessories = []; this.externalAccessories = []; this.log.debug('Finished initializing platform:', this.config.name); this.api.on('didFinishLaunching', () => { this.discoverAVR(); }); } configureAccessory(accessory) { this.log.info('Loading accessory from cache:', accessory.displayName); this.platformAccessories.push(accessory); } async discoverAVR() { require('events').EventEmitter.prototype._maxListeners = 50; for (const device of this.config.accessories) { await this.createZoneAccessories(device); } } async createZoneAccessories(device) { let controller = new controller_1.DenonMarantzController(this.log, device.ip); const avrAccessoryMain = await this.createAVRAccessory(device, controller, 'main'); this.externalAccessories.push(avrAccessoryMain); if (device.zone2enabled) { const avrAccessoryZone2 = await this.createAVRAccessory(device, controller, 'zone2'); this.externalAccessories.push(avrAccessoryZone2); } this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, this.externalAccessories); // strictly required for AVR or TV to be shown } async createAVRAccessory(device, controller, zone) { let uuid = `${device.ip}_${zone}`; uuid = this.api.hap.uuid.generate(uuid); const existingAccessory = this.platformAccessories.find(accessory => accessory.UUID === uuid); if (existingAccessory) { this.log.info(`restoring from cache ${device.displayName}, with ip ${device.ip}`); new accessory_1.DenonMarantzAVRAccessory(this.log, this, existingAccessory, zone, controller); return existingAccessory; } else { ~this.log.info(`adding accessory ${device.displayName}, with ip ${device.ip}`); const accessory = new this.api.platformAccessory(device.zone2enabled ? `${device.displayName} ${zone}` : device.displayName, uuid, 34 /* this.api.hap.Categories.AUDIO_RECEIVER */); accessory.context = { device }; new accessory_1.DenonMarantzAVRAccessory(this.log, this, accessory, zone, controller); return accessory; } } } exports.DenonMarantzAVRPlatform = DenonMarantzAVRPlatform; //# sourceMappingURL=platform.js.map