fix: ensure no charging profile purpose TxProfile is loaded at startup
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 9 Jun 2024 13:52:02 +0000 (15:52 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 9 Jun 2024 13:52:02 +0000 (15:52 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts

index 47e911a4befd5a6a8b99a07bdd84a0566c2d86a9..7dbb0d3ebd7f7ae2900885f8e7706daa56e30b36 100644 (file)
@@ -131,7 +131,7 @@ import {
   hasFeatureProfile,
   hasReservationExpired,
   initializeConnectorsMapStatus,
-  prepareDatesInConnectorStatus,
+  prepareConnectorStatus,
   propagateSerialNumber,
   setChargingStationOptions,
   stationTemplateToStationInfo,
@@ -1480,7 +1480,7 @@ export class ChargingStation extends EventEmitter {
       for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) {
         this.connectors.set(
           connectorId,
-          prepareDatesInConnectorStatus(clone<ConnectorStatus>(connectorStatus))
+          prepareConnectorStatus(clone<ConnectorStatus>(connectorStatus))
         )
       }
     } else if (configuration.evsesStatus != null && configuration.connectorsStatus == null) {
@@ -1493,7 +1493,7 @@ export class ChargingStation extends EventEmitter {
             // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
             evseStatusConfiguration.connectorsStatus!.map((connectorStatus, connectorId) => [
               connectorId,
-              prepareDatesInConnectorStatus(connectorStatus)
+              prepareConnectorStatus(connectorStatus)
             ])
           )
         })
index 4d6a477c44e5ea3ced3cab1f13d986814651b147..01c7f2921080f485f92b87af14dbd44882fcaf50 100644 (file)
@@ -436,22 +436,25 @@ export const resetConnectorStatus = (connectorStatus: ConnectorStatus | undefine
   delete connectorStatus.transactionBeginMeterValue
 }
 
-export const prepareDatesInConnectorStatus = (
-  connectorStatus: ConnectorStatus
-): ConnectorStatus => {
+export const prepareConnectorStatus = (connectorStatus: ConnectorStatus): ConnectorStatus => {
   if (connectorStatus.reservation != null) {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     connectorStatus.reservation.expiryDate = convertToDate(connectorStatus.reservation.expiryDate)!
   }
   if (isNotEmptyArray(connectorStatus.chargingProfiles)) {
-    connectorStatus.chargingProfiles = connectorStatus.chargingProfiles.map(chargingProfile => {
-      chargingProfile.chargingSchedule.startSchedule = convertToDate(
-        chargingProfile.chargingSchedule.startSchedule
+    connectorStatus.chargingProfiles = connectorStatus.chargingProfiles
+      .filter(
+        chargingProfile =>
+          chargingProfile.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE
       )
-      chargingProfile.validFrom = convertToDate(chargingProfile.validFrom)
-      chargingProfile.validTo = convertToDate(chargingProfile.validTo)
-      return chargingProfile
-    })
+      .map(chargingProfile => {
+        chargingProfile.chargingSchedule.startSchedule = convertToDate(
+          chargingProfile.chargingSchedule.startSchedule
+        )
+        chargingProfile.validFrom = convertToDate(chargingProfile.validFrom)
+        chargingProfile.validTo = convertToDate(chargingProfile.validTo)
+        return chargingProfile
+      })
   }
   return connectorStatus
 }