@jabrown93/homebridge-onkyo
Version:
Homebridge plugin for Onkyo Receivers
58 lines • 2.44 kB
JavaScript
import { Eiscp } from './eiscp/eiscp.js';
import { OnkyoReceiver } from './onkyoReceiver.js';
export class OnkyoPlatform {
api;
config;
log;
receiverAccessories;
accessories;
existingAccessories;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
connections;
numberReceivers;
constructor(log, config, api) {
this.api = api;
this.config = config;
this.log = log;
this.existingAccessories = new Map();
this.accessories = [];
this.connections = {};
this.receiverAccessories = [];
if (this.config === undefined) {
this.log.error('ERROR: your configuration is incorrect. Configuration changed with version 0.7.x');
throw new Error('ERROR: your configuration is incorrect. Configuration changed with version 0.7.x');
}
this.log.info('Finished initializing platform:', this.config.name);
this.api.on('didFinishLaunching', () => {
this.log.debug('Executed didFinishLaunching callback');
this.createAccessories();
});
}
configureAccessory(accessory) {
this.existingAccessories.set(accessory.UUID, accessory);
}
createAccessories() {
this.numberReceivers = this.config.receivers.length;
this.log.debug('Creating %s receivers...', this.numberReceivers);
if (this.numberReceivers === 0) {
return;
}
this.config.receivers.forEach(receiver => {
if (!this.connections[receiver.ip_address]) {
this.log.debug('Creating new connection for ip %s', receiver.ip_address);
this.connections[receiver.ip_address] = new Eiscp(this.log);
this.connections[receiver.ip_address].connect({
host: receiver['ip_address'],
reconnect: true,
model: receiver['model'],
});
}
const uuid = this.api.hap.uuid.generate('homebridge:homebridge-onkyo' + receiver.name);
const accessory = this.existingAccessories.get(uuid) ??
new this.api.platformAccessory(receiver.name, uuid, 34 /* this.api.hap.Categories.AUDIO_RECEIVER */);
const onkyoReceiver = new OnkyoReceiver(this, receiver, accessory);
this.receiverAccessories.push(onkyoReceiver);
});
}
}
//# sourceMappingURL=onkyoPlatform.js.map