Merge dependabot/npm_and_yarn/typescript-eslint/parser-6.7.5 into combined-prs-branch
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index f1e0e022ce842c023c962714805c93d271627bbf..c6a5278edccc1b5f9e324fff5584f32c3e042fde 100644 (file)
@@ -144,6 +144,8 @@ import {
   isUndefined,
   logPrefix,
   logger,
+  min,
+  once,
   roundTo,
   secureRandom,
   sleep,
@@ -159,7 +161,7 @@ export class ChargingStation {
   public idTagsCache: IdTagsCache;
   public automaticTransactionGenerator!: AutomaticTransactionGenerator | undefined;
   public ocppConfiguration!: ChargingStationOcppConfiguration | undefined;
-  public wsConnection!: WebSocket | null;
+  public wsConnection: WebSocket | null;
   public readonly connectors: Map<number, ConnectorStatus>;
   public readonly evses: Map<number, EvseStatus>;
   public readonly requests: Map<string, CachedRequest>;
@@ -191,6 +193,7 @@ export class ChargingStation {
     this.started = false;
     this.starting = false;
     this.stopping = false;
+    this.wsConnection = null;
     this.wsConnectionRestarted = false;
     this.autoReconnectRetryCount = 0;
     this.index = index;
@@ -379,7 +382,7 @@ export class ChargingStation {
     const connectorMaximumPower = this.getMaximumPower() / this.powerDivider;
     const connectorChargingProfilesPowerLimit =
       getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId);
-    return Math.min(
+    return min(
       isNaN(connectorMaximumPower) ? Infinity : connectorMaximumPower,
       isNaN(connectorAmperageLimitationPowerLimit!)
         ? Infinity
@@ -1017,8 +1020,7 @@ export class ChargingStation {
   }
 
   private startReservationExpirationSetInterval(customInterval?: number): void {
-    const interval =
-      customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_OBSERVATION_INTERVAL;
+    const interval = customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_INTERVAL;
     if (interval > 0) {
       logger.info(
         `${this.logPrefix()} Reservation expiration date checks started every ${formatDurationMilliSeconds(
@@ -1032,7 +1034,7 @@ export class ChargingStation {
   }
 
   private stopReservationExpirationSetInterval(): void {
-    if (this.reservationExpirationSetInterval) {
+    if (!isNullOrUndefined(this.reservationExpirationSetInterval)) {
       clearInterval(this.reservationExpirationSetInterval);
     }
   }
@@ -1126,7 +1128,8 @@ export class ChargingStation {
   private getStationInfoFromTemplate(): ChargingStationInfo {
     const stationTemplate: ChargingStationTemplate = this.getTemplateFromFile()!;
     checkTemplate(stationTemplate, this.logPrefix(), this.templateFile);
-    warnTemplateKeysDeprecation(stationTemplate, this.logPrefix(), this.templateFile);
+    const warnTemplateKeysDeprecationOnce = once(warnTemplateKeysDeprecation, this);
+    warnTemplateKeysDeprecationOnce(stationTemplate, this.logPrefix(), this.templateFile);
     if (stationTemplate?.Connectors) {
       checkConnectorsConfiguration(stationTemplate, this.logPrefix(), this.templateFile);
     }
@@ -1697,7 +1700,7 @@ export class ChargingStation {
             const beginId = PerformanceStatistics.beginMeasure(measureId);
             writeFileSync(
               this.configurationFile,
-              JSON.stringify(configurationData, null, 2),
+              JSON.stringify(configurationData, undefined, 2),
               'utf8',
             );
             PerformanceStatistics.endMeasure(measureId, beginId);