refactor: improve start transaction sanity checks log messages
[e-mobility-charging-stations-simulator.git] / src / charging-station / Helpers.ts
index dd6bcee18fe5ccdf798e18e2df09a70ecebca3ff..936c1a7d65a9136dbd11843c915f91a8d334f0b6 100644 (file)
@@ -339,6 +339,12 @@ export const initializeConnectorsMapStatus = (
 };
 
 export const resetConnectorStatus = (connectorStatus: ConnectorStatus): void => {
+  connectorStatus.chargingProfiles =
+    connectorStatus.transactionId && isNotEmptyArray(connectorStatus.chargingProfiles)
+      ? connectorStatus.chargingProfiles?.filter(
+          (chargingProfile) => chargingProfile.transactionId !== connectorStatus.transactionId,
+        )
+      : [];
   connectorStatus.idTagLocalAuthorized = false;
   connectorStatus.idTagAuthorized = false;
   connectorStatus.transactionRemoteStarted = false;
@@ -517,7 +523,7 @@ export const getAmperageLimitationUnitDivider = (stationInfo: ChargingStationInf
 
 /**
  * Gets the connector cloned charging profiles applying a power limitation
- * and sorted by connector id ascending then stack level descending
+ * and sorted by connector id descending then stack level descending
  *
  * @param chargingStation -
  * @param connectorId -
@@ -528,10 +534,10 @@ export const getConnectorChargingProfiles = (
   connectorId: number,
 ) => {
   return cloneObject<ChargingProfile[]>(
-    (chargingStation.getConnectorStatus(0)?.chargingProfiles ?? [])
+    (chargingStation.getConnectorStatus(connectorId)?.chargingProfiles ?? [])
       .sort((a, b) => b.stackLevel - a.stackLevel)
       .concat(
-        (chargingStation.getConnectorStatus(connectorId)?.chargingProfiles ?? []).sort(
+        (chargingStation.getConnectorStatus(0)?.chargingProfiles ?? []).sort(
           (a, b) => b.stackLevel - a.stackLevel,
         ),
       ),
@@ -735,7 +741,7 @@ interface ChargingProfilesLimit {
 }
 
 /**
- * Charging profiles shall already be sorted by connector id ascending then stack level descending
+ * Charging profiles shall already be sorted by connector id descending then stack level descending
  *
  * @param chargingStation -
  * @param connectorId -
@@ -961,7 +967,10 @@ const canProceedRecurringChargingProfile = (
     );
     return false;
   }
-  if (isNullOrUndefined(chargingProfile.chargingSchedule.startSchedule)) {
+  if (
+    chargingProfile.chargingProfileKind === ChargingProfileKindType.RECURRING &&
+    isNullOrUndefined(chargingProfile.chargingSchedule.startSchedule)
+  ) {
     logger.error(
       `${logPrefix} ${moduleName}.canProceedRecurringChargingProfile: Recurring charging profile id ${chargingProfile.chargingProfileId} has no startSchedule defined`,
     );