fix: fix station info generation
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 23:24:21 +0000 (01:24 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 23:24:21 +0000 (01:24 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/types/ChargingStationInfo.ts
ui/web/src/types/ChargingStationType.ts

index 5d400371eadecdafd84ea75723ae1c3875ee050f..b27f5b2e67b2110365626bc8cd369ed2a4d5dd52 100644 (file)
@@ -993,18 +993,22 @@ export class ChargingStation {
     stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime)
       ? stationTemplate.resetTime * 1000
       : Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
-    // Initialize evses or connectors if needed (FIXME: should be factored out)
+    // Initialize evses or connectors if needed (FIXME: should be factored out but connectors and evses configuration are only available in templates)
     this.initializeConnectorsOrEvses(stationInfo);
     stationInfo.maximumAmperage = this.getMaximumAmperage(stationInfo);
-    ChargingStationUtils.createStationInfoHash(stationInfo);
+    delete stationInfo?.Connectors;
+    delete stationInfo?.Evses;
     return stationInfo;
   }
 
   private getStationInfoFromFile(): ChargingStationInfo | undefined {
     let stationInfo: ChargingStationInfo | undefined;
-    this.getStationInfoPersistentConfiguration() &&
-      (stationInfo = this.getConfigurationFromFile()?.stationInfo);
-    stationInfo && ChargingStationUtils.createStationInfoHash(stationInfo);
+    if (this.getStationInfoPersistentConfiguration()) {
+      stationInfo = this.getConfigurationFromFile()?.stationInfo;
+      if (stationInfo) {
+        delete stationInfo?.infoHash;
+      }
+    }
     return stationInfo;
   }
 
@@ -1014,11 +1018,7 @@ export class ChargingStation {
     // Priority:
     // 1. charging station info from template
     // 2. charging station info from configuration file
-    // 3. charging station info attribute
     if (stationInfoFromFile?.templateHash === stationInfoFromTemplate.templateHash) {
-      if (this.stationInfo?.infoHash === stationInfoFromFile?.infoHash) {
-        return this.stationInfo;
-      }
       return stationInfoFromFile;
     }
     stationInfoFromFile &&
@@ -1075,9 +1075,6 @@ export class ChargingStation {
       this.stationInfo.firmwareVersion = match?.join('.');
     }
     this.saveStationInfo();
-    // Avoid duplication of connectors or evses related information in RAM
-    delete this.stationInfo?.Connectors;
-    delete this.stationInfo?.Evses;
     this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl();
     if (this.getEnableStatistics() === true) {
       this.performanceStatistics = PerformanceStatistics.getInstance(
index c58db0ceec198b570bd90dd8e6a8e91b3c3fbc6e..cac243ff883c380984f71ece085c2116d402ffdd 100644 (file)
@@ -387,14 +387,6 @@ export class ChargingStationUtils {
     return stationTemplate as unknown as ChargingStationInfo;
   }
 
-  public static createStationInfoHash(stationInfo: ChargingStationInfo): void {
-    delete stationInfo.infoHash;
-    stationInfo.infoHash = crypto
-      .createHash(Constants.DEFAULT_HASH_ALGORITHM)
-      .update(JSON.stringify(stationInfo))
-      .digest('hex');
-  }
-
   public static createSerialNumber(
     stationTemplate: ChargingStationTemplate,
     stationInfo: ChargingStationInfo,
@@ -406,27 +398,18 @@ export class ChargingStationUtils {
       randomSerialNumber: true,
     }
   ): void {
-    params = params ?? {};
-    params.randomSerialNumberUpperCase = params?.randomSerialNumberUpperCase ?? true;
-    params.randomSerialNumber = params?.randomSerialNumber ?? true;
+    params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params };
     const serialNumberSuffix = params?.randomSerialNumber
       ? ChargingStationUtils.getRandomSerialNumberSuffix({
           upperCase: params.randomSerialNumberUpperCase,
         })
       : '';
-    stationInfo.chargePointSerialNumber = Utils.isNotEmptyString(
-      stationTemplate?.chargePointSerialNumberPrefix
-    )
-      ? `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`
-      : undefined;
-    stationInfo.chargeBoxSerialNumber = Utils.isNotEmptyString(
-      stationTemplate?.chargeBoxSerialNumberPrefix
-    )
-      ? `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`
-      : undefined;
-    stationInfo.meterSerialNumber = Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix)
-      ? `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`
-      : undefined;
+    Utils.isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) &&
+      (stationInfo.chargePointSerialNumber = `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`);
+    Utils.isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) &&
+      (stationInfo.chargeBoxSerialNumber = `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`);
+    Utils.isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) &&
+      (stationInfo.meterSerialNumber = `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`);
   }
 
   public static propagateSerialNumber(
index 4f5336233dde7819e6f75a54caf505538876df35..1d91b37502ee76ee93053e00343d1a3fb86df64f 100644 (file)
@@ -20,6 +20,7 @@ export type ChargingStationInfo = Omit<
   | 'meterSerialNumberPrefix'
 > & {
   hashId: string;
+  /** @deprecated Use hashId instead */
   infoHash?: string;
   chargingStationId?: string;
   chargeBoxSerialNumber?: string;
index e9f5f108afffc67ede6edb30133506d0868cb328..b391bef5188f2497b139e42105c85ec93f3268ce 100644 (file)
@@ -23,7 +23,6 @@ export type ChargingStationInfo = {
   firmwareVersion?: string;
   numberOfConnectors?: number | number[];
   baseName: string;
-  infoHash?: string;
   templateHash?: string;
   chargeBoxSerialNumber?: string;
   chargePointSerialNumber?: string;