Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Add support for CS info configuration file change detection
Browse files Browse the repository at this point in the history
Taken now into account at simulated reset

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Apr 25, 2022
1 parent c5a22ef commit f765bea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
36 changes: 24 additions & 12 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,14 @@ export default class ChargingStation {
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(),
Expand Down Expand Up @@ -943,12 +949,7 @@ export default class ChargingStation {
}

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(
Expand Down Expand Up @@ -982,8 +983,13 @@ export default class ChargingStation {
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 {
Expand All @@ -996,11 +1002,17 @@ export default class ChargingStation {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/types/ChargingStationInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ChargingStationTemplate from './ChargingStationTemplate';

export default interface ChargingStationInfo extends ChargingStationTemplate {
hash?: string;
infoHash?: string;
chargingStationId?: string;
chargeBoxSerialNumber?: string;
chargePointSerialNumber?: string;
Expand Down
1 change: 1 addition & 0 deletions src/types/ChargingStationTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface AutomaticTransactionGenerator {
export type WsOptions = ClientOptions & ClientRequestArgs;

export default interface ChargingStationTemplate {
templateHash?: string;
supervisionUrls?: string | string[];
supervisionUrlOcppConfiguration?: boolean;
supervisionUrlOcppKey?: string;
Expand Down

0 comments on commit f765bea

Please sign in to comment.