+ this.saveConfiguration();
+ }
+
+ private getConfigurationFromTemplate(): ChargingStationConfiguration {
+ return this.stationInfo.Configuration ?? ({} as ChargingStationConfiguration);
+ }
+
+ private getConfigurationFromFile(): ChargingStationConfiguration | null {
+ let configuration: ChargingStationConfiguration = null;
+ if (this.configurationFile && fs.existsSync(this.configurationFile)) {
+ try {
+ const fileDescriptor = fs.openSync(this.configurationFile, 'r');
+ configuration = JSON.parse(
+ fs.readFileSync(fileDescriptor, 'utf8')
+ ) as ChargingStationConfiguration;
+ fs.closeSync(fileDescriptor);
+ } catch (error) {
+ FileUtils.handleFileException(
+ this.logPrefix(),
+ 'Configuration',
+ this.configurationFile,
+ error as NodeJS.ErrnoException
+ );
+ }
+ }
+ return configuration;
+ }
+
+ private saveConfiguration(): void {
+ if (this.configurationFile) {
+ try {
+ if (!fs.existsSync(path.dirname(this.configurationFile))) {
+ fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
+ }
+ const fileDescriptor = fs.openSync(this.configurationFile, 'w');
+ fs.writeFileSync(fileDescriptor, JSON.stringify(this.configuration, null, 2));
+ fs.closeSync(fileDescriptor);
+ } catch (error) {
+ FileUtils.handleFileException(
+ this.logPrefix(),
+ 'Configuration',
+ this.configurationFile,
+ error as NodeJS.ErrnoException
+ );
+ }
+ } else {
+ logger.error(
+ `${this.logPrefix()} Trying to save charging station configuration to undefined file`
+ );
+ }
+ }
+
+ private getConfiguration(): ChargingStationConfiguration {
+ let configuration: ChargingStationConfiguration = this.getConfigurationFromFile();
+ if (!configuration) {
+ configuration = this.getConfigurationFromTemplate();
+ }
+ return configuration;