refactor: cleanup charging station options handling
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 11 Feb 2024 12:22:30 +0000 (13:22 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 11 Feb 2024 12:22:30 +0000 (13:22 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts
src/charging-station/IdTagsCache.ts

index 2b5b5f8376fca34c915965ab1b0d46df590ef6ad..8a5c5c6fba84ed66b0fb33a32de578bcc3f4ee62 100644 (file)
@@ -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) &&
index df3d03082ea3053969c386b8e9c39300426c5e39..bf118e9fbb4f9a13111d57c1cc332a3cedd2225c 100644 (file)
@@ -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<number, ConnectorStatus>,
   logPrefix: string
index d1ad32d2bbffe63aa4d091fe11fecce1af0db165..e1bc8b843eb124e822eea882e900210112710cdd 100644 (file)
@@ -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,