fix: fix circular dependencies in types
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 6f4b4a130d0214095ab7c86fff4538b98f1ee1a8..f1dac8a3a97ab54f0ff6a1042a879570044d96e3 100644 (file)
@@ -25,7 +25,7 @@ import {
   deleteConfigurationKey,
   getConfigurationKey,
   setConfigurationKeyValue,
-} from './ChargingStationConfigurationUtils';
+} from './ChargingStationConfigurationKeyUtils';
 import {
   buildConnectorsMap,
   checkConnectorsConfiguration,
@@ -43,6 +43,7 @@ import {
   getIdTagsFile,
   getMaxNumberOfEvses,
   getPhaseRotationValue,
+  hasFeatureProfile,
   initializeConnectorsMapStatus,
   propagateSerialNumber,
   stationTemplateToStationInfo,
@@ -668,7 +669,7 @@ export class ChargingStation {
         if (this.getEnableStatistics() === true) {
           this.performanceStatistics?.start();
         }
-        if (this.hasFeatureProfile(SupportedFeatureProfiles.Reservation)) {
+        if (hasFeatureProfile(this, SupportedFeatureProfiles.Reservation)) {
           this.startReservationExpirationSetInterval();
         }
         this.openWSConnection();
@@ -731,7 +732,7 @@ export class ChargingStation {
         if (this.getEnableStatistics() === true) {
           this.performanceStatistics?.stop();
         }
-        if (this.hasFeatureProfile(SupportedFeatureProfiles.Reservation)) {
+        if (hasFeatureProfile(this, SupportedFeatureProfiles.Reservation)) {
           this.stopReservationExpirationSetInterval();
         }
         this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash);
@@ -763,13 +764,6 @@ export class ChargingStation {
     }
   }
 
-  public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean | undefined {
-    return getConfigurationKey(
-      this,
-      StandardParametersKey.SupportedFeatureProfiles,
-    )?.value?.includes(featureProfile);
-  }
-
   public bufferMessage(message: string): void {
     this.messageBuffer.add(message);
   }
@@ -973,8 +967,6 @@ export class ChargingStation {
     const connector = this.getConnectorStatus(reservation.connectorId)!;
     switch (reason) {
       case ReservationTerminationReason.CONNECTOR_STATE_CHANGED:
-        delete connector.reservation;
-        break;
       case ReservationTerminationReason.TRANSACTION_STARTED:
         delete connector.reservation;
         break;
@@ -1021,7 +1013,7 @@ export class ChargingStation {
   ): [boolean, Reservation | undefined] {
     const foundReservation = this.getReservationBy(
       ReservationFilterKey.RESERVATION_ID,
-      reservation.id!,
+      reservation.reservationId!,
     );
     return isUndefined(foundReservation) ? [false, undefined] : [true, foundReservation];
   }
@@ -1110,9 +1102,11 @@ export class ChargingStation {
 
   private getNumberOfReservationsOnConnectorZero(): number {
     let numberOfReservations = 0;
-    if (this.hasEvses && this.evses.get(0)?.connectors.get(0)?.reservation) {
-      ++numberOfReservations;
-    } else if (this.connectors.get(0)?.reservation) {
+    if (
+      // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
+      (this.hasEvses && this.evses.get(0)?.connectors.get(0)?.reservation) ||
+      (!this.hasEvses && this.connectors.get(0)?.reservation)
+    ) {
       ++numberOfReservations;
     }
     return numberOfReservations;