UNPKG

homebridge-denon-v3

Version:

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

91 lines 4.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DenonMarantzAVRPlatform = void 0; const accessory_1 = require("./accessory"); const controller_1 = require("./controller"); // import { YamahaVolumeAccessory } from './volumeAccessory.js'; const settings_1 = require("./settings"); class DenonMarantzAVRPlatform { // public readonly externalAccessories: PlatformAccessory[] = []; 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.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() { // try { // const baseApiUrl = `http://${this.config.ip}/YamahaExtendedControl/v1`; // const deviceInfoResponse = await fetch(`${baseApiUrl}/system/getDeviceInfo`); // const deviceInfo = (await deviceInfoResponse.json()) as DeviceInfo; // const featuresResponse = await fetch(`${baseApiUrl}/system/getFeatures`); // const features = (await featuresResponse.json()) as Features; // if (deviceInfo.response_code !== 0) { // throw new Error(); // } // const device: AccessoryContext['device'] = { // displayName: this.config.name ?? `Yamaha ${deviceInfo.model_name}`, // modelName: deviceInfo.model_name, // systemId: deviceInfo.system_id, // firmwareVersion: deviceInfo.system_version, // baseApiUrl, // }; // if (this.config.enablePureDirectSwitch) { // await this.createPureDirectAccessory(device); // } // await this.createZoneAccessories(device, 'main'); // features.zone.length > 1 && (await this.createZoneAccessories(device, 'zone2')); // features.zone.length > 2 && (await this.createZoneAccessories(device, 'zone3')); // features.zone.length > 3 && (await this.createZoneAccessories(device, 'zone4')); // if (this.externalAccessories.length > 0) { // this.api.publishExternalAccessories(PLUGIN_NAME, this.externalAccessories); // } // } catch { // this.log.error(` // Failed to get system config from ${this.config.name}. Please verify the AVR is connected and accessible at ${this.config.ip} // `); // } // loop over the discovered devices and register each one if it has not already been registered for (const device of this.config.accessories) { await this.createZoneAccessories(device); } } async createZoneAccessories(device) { let controller = new controller_1.DenonMarantzController(this.log, device.ip); await this.createAVRAccessory(device, controller, 'main'); // await this.createVolumeAccessory(device, 'main'); if (device.zone2enabled) { await this.createAVRAccessory(device, controller, 'zone2'); // await this.createVolumeAccessory(device, 'zone2'); } } 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); } 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); this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]); return accessory; } } } exports.DenonMarantzAVRPlatform = DenonMarantzAVRPlatform; //# sourceMappingURL=platform.js.map