From: Jérôme Benoit Date: Sun, 11 Feb 2024 12:22:30 +0000 (+0100) Subject: refactor: cleanup charging station options handling X-Git-Tag: v1.2.36~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=36b73d95deccfb6538929c48e0f989fb1c696e8a;p=e-mobility-charging-stations-simulator.git refactor: cleanup charging station options handling Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 2b5b5f83..8a5c5c6f 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -42,6 +42,7 @@ import { hasReservationExpired, initializeConnectorsMapStatus, propagateSerialNumber, + setChargingStationOptions, stationTemplateToStationInfo, warnTemplateKeysDeprecation } from './Helpers.js' @@ -1229,11 +1230,10 @@ export class ChargingStation extends EventEmitter { return stationInfo } - private getStationInfo (stationInfoPersistentConfiguration?: boolean): ChargingStationInfo { + private getStationInfo (options?: ChargingStationOptions): ChargingStationInfo { const stationInfoFromTemplate = this.getStationInfoFromTemplate() - stationInfoPersistentConfiguration != null && - (stationInfoFromTemplate.stationInfoPersistentConfiguration = - stationInfoPersistentConfiguration) + options?.persistentConfiguration != null && + (stationInfoFromTemplate.stationInfoPersistentConfiguration = options.persistentConfiguration) const stationInfoFromFile = this.getStationInfoFromFile( stationInfoFromTemplate.stationInfoPersistentConfiguration ) @@ -1244,7 +1244,10 @@ export class ChargingStation extends EventEmitter { stationInfoFromFile != null && stationInfoFromFile.templateHash === stationInfoFromTemplate.templateHash ) { - return { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromFile } + return setChargingStationOptions( + { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromFile }, + options + ) } stationInfoFromFile != null && propagateSerialNumber( @@ -1252,7 +1255,10 @@ export class ChargingStation extends EventEmitter { stationInfoFromFile, stationInfoFromTemplate ) - return { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromTemplate } + return setChargingStationOptions( + { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromTemplate }, + options + ) } private saveStationInfo (): void { @@ -1285,24 +1291,7 @@ export class ChargingStation extends EventEmitter { } else { this.initializeConnectorsOrEvsesFromTemplate(stationTemplate) } - this.stationInfo = this.getStationInfo(options?.persistentConfiguration) - if (options?.persistentConfiguration != null) { - this.stationInfo.ocppPersistentConfiguration = options.persistentConfiguration - this.stationInfo.automaticTransactionGeneratorPersistentConfiguration = - options.persistentConfiguration - } - if (options?.autoRegister != null) { - this.stationInfo.autoRegister = options.autoRegister - } - if (options?.enableStatistics != null) { - this.stationInfo.enableStatistics = options.enableStatistics - } - if (options?.ocppStrictCompliance != null) { - this.stationInfo.ocppStrictCompliance = options.ocppStrictCompliance - } - if (options?.stopTransactionsOnStopped != null) { - this.stationInfo.stopTransactionsOnStopped = options.stopTransactionsOnStopped - } + this.stationInfo = this.getStationInfo(options) if ( this.stationInfo.firmwareStatus === FirmwareStatus.Installing && isNotEmptyString(this.stationInfo.firmwareVersionPattern) && diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index df3d0308..bf118e9f 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -36,6 +36,7 @@ import { type ChargingSchedulePeriod, type ChargingStationConfiguration, type ChargingStationInfo, + type ChargingStationOptions, type ChargingStationTemplate, type ChargingStationWorkerMessageEvents, ConnectorPhaseRotation, @@ -333,6 +334,30 @@ export const buildConnectorsMap = ( return connectorsMap } +export const setChargingStationOptions = ( + stationInfo: ChargingStationInfo, + options?: ChargingStationOptions +): ChargingStationInfo => { + if (options?.persistentConfiguration != null) { + stationInfo.ocppPersistentConfiguration = options.persistentConfiguration + stationInfo.automaticTransactionGeneratorPersistentConfiguration = + options.persistentConfiguration + } + if (options?.autoRegister != null) { + stationInfo.autoRegister = options.autoRegister + } + if (options?.enableStatistics != null) { + stationInfo.enableStatistics = options.enableStatistics + } + if (options?.ocppStrictCompliance != null) { + stationInfo.ocppStrictCompliance = options.ocppStrictCompliance + } + if (options?.stopTransactionsOnStopped != null) { + stationInfo.stopTransactionsOnStopped = options.stopTransactionsOnStopped + } + return stationInfo +} + export const initializeConnectorsMapStatus = ( connectors: Map, logPrefix: string diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index d1ad32d2..e1bc8b84 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -143,8 +143,7 @@ export class IdTagsCache { logger.debug( `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload` ) - this.deleteIdTagsCache(file) - this.deleteIdTagsCacheIndexes(file) + this.deleteIdTags(file) } catch (error) { handleFileException( file,