try {
const measureId = `${FileType.ChargingStationTemplate} read`;
const beginId = PerformanceStatistics.beginMeasure(measureId);
- template = JSON.parse(fs.readFileSync(this.templateFile, 'utf8')) as ChargingStationTemplate;
+ template =
+ (JSON.parse(fs.readFileSync(this.templateFile, 'utf8')) as ChargingStationTemplate) ??
+ ({} as ChargingStationTemplate);
PerformanceStatistics.endMeasure(measureId, beginId);
+ template.templateHash = crypto
+ .createHash(Constants.DEFAULT_HASH_ALGORITHM)
+ .update(JSON.stringify(template))
+ .digest('hex');
} catch (error) {
FileUtils.handleFileException(
this.logPrefix(),
}
private getStationInfoFromTemplate(): ChargingStationInfo {
- const stationInfo: ChargingStationInfo =
- this.getTemplateFromFile() ?? ({} as ChargingStationInfo);
- stationInfo.hash = crypto
- .createHash(Constants.DEFAULT_HASH_ALGORITHM)
- .update(JSON.stringify(stationInfo))
- .digest('hex');
+ const stationInfo: ChargingStationInfo = this.getTemplateFromFile();
const chargingStationId = this.getChargingStationId(stationInfo);
// Deprecation template keys section
this.warnDeprecatedTemplateKey(
return stationInfo;
}
- private getStationInfoFromFile(): ChargingStationInfo | null {
- return this.getConfigurationFromFile()?.stationInfo ?? null;
+ private getStationInfoFromFile(): ChargingStationInfo {
+ const stationInfo = this.getConfigurationFromFile()?.stationInfo ?? ({} as ChargingStationInfo);
+ stationInfo.infoHash = crypto
+ .createHash(Constants.DEFAULT_HASH_ALGORITHM)
+ .update(JSON.stringify(stationInfo))
+ .digest('hex');
+ return stationInfo;
}
private getStationInfo(): ChargingStationInfo {
this.hashId + '.json'
);
const stationInfoFromFile: ChargingStationInfo = this.getStationInfoFromFile();
- if (stationInfoFromFile?.hash === stationInfoFromTemplate.hash) {
+ // Priority: charging stations info from template > charging station info from configuration file > charging station info attribute
+ if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) {
return stationInfoFromFile;
+ } else if (stationInfoFromFile?.templateHash !== stationInfoFromTemplate.templateHash) {
+ this.createSerialNumber(stationInfoFromTemplate, stationInfoFromFile);
+ return stationInfoFromTemplate;
+ }
+ if (this.stationInfo?.infoHash === stationInfoFromFile?.infoHash) {
+ return this.stationInfo;
}
- this.createSerialNumber(stationInfoFromTemplate, stationInfoFromFile);
- return stationInfoFromTemplate;
+ return stationInfoFromFile;
}
private saveStationInfo(): void {