@petro-kushchak/homebridge-homepod-radio
Version:
Homebridge accessory for streaming radio to Homepod Mini and Apple TV
67 lines • 2.38 kB
JavaScript
import { PLUGIN_MODEL } from './platformConstants.js';
export class HomepodRadioPlatformConfig {
config;
name;
homepodId;
serialNumber;
verboseMode;
radios;
audioFiles;
mediaPath;
httpPort;
enableVolumeControl;
volume;
constructor(config) {
this.config = config;
this.name = config.name || 'HomePod Mini Radio';
this.radios = [];
this.audioFiles = [];
if (!config.homepodId) {
throw 'Missing "homepodId" setting!';
}
this.homepodId = config.homepodId;
this.serialNumber = config.serialNumber || `HPD-${this.homepodId}`;
this.verboseMode = (config.enableVolumeControl ??= false);
this.httpPort = this.config.httpPort || 4567;
this.mediaPath = this.config.mediaPath || '';
this.enableVolumeControl = (this.config.enableVolumeControl ??= false);
this.volume = this.config.volume || 25;
this.loadRadioConfigs();
this.loadAudioConfigs();
}
loadAudioConfigs() {
if (this.config.audioFiles) {
this.config.audioFiles.forEach((audioConfig) => {
const audioFile = {
name: audioConfig.name,
fileName: audioConfig.fileName,
volume: audioConfig.volume || 0,
};
this.audioFiles.push(audioFile);
});
}
}
loadRadioConfigs() {
if (this.config.radios) {
this.config.radios.forEach((radioConfig) => {
const radio = {
name: radioConfig.name,
model: radioConfig.model || PLUGIN_MODEL,
radioUrl: radioConfig.radioUrl,
trackName: radioConfig.trackName || radioConfig.name,
serialNumber: this.serialNumber,
autoResume: radioConfig.autoResume || false,
metadataUrl: radioConfig.metadataUrl || '',
artworkUrl: radioConfig.artworkUrl || '',
onSwitch: radioConfig.onSwitch || false,
volume: radioConfig.volume || 0,
};
this.radios.push(radio);
});
}
}
getRadioNames() {
return this.radios.map((r) => r.name);
}
}
//# sourceMappingURL=platformConfig.js.map