refactor(simulator): refine LRU cache type name
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 9a53a2e4a61dcc0bb0484d68565c7409343f02fc..e78d6bf87bfb50715b884f300db97dca19ac7ce6 100644 (file)
@@ -47,7 +47,7 @@ import {
   type ChargingStationOcppConfiguration,
   type ChargingStationTemplate,
   ConnectorPhaseRotation,
-  ConnectorStatus,
+  type ConnectorStatus,
   ConnectorStatusEnum,
   CurrentType,
   type ErrorCallback,
@@ -74,7 +74,6 @@ import {
   RegistrationStatusEnumType,
   RequestCommand,
   type Response,
-  type ResponseCallback,
   StandardParametersKey,
   type StatusNotificationRequest,
   type StatusNotificationResponse,
@@ -387,6 +386,30 @@ export class ChargingStation {
     return localAuthListEnabled ? Utils.convertToBoolean(localAuthListEnabled.value) : false;
   }
 
+  public getHeartbeatInterval(): number {
+    const HeartbeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
+      this,
+      StandardParametersKey.HeartbeatInterval
+    );
+    if (HeartbeatInterval) {
+      return Utils.convertToInt(HeartbeatInterval.value) * 1000;
+    }
+    const HeartBeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
+      this,
+      StandardParametersKey.HeartBeatInterval
+    );
+    if (HeartBeatInterval) {
+      return Utils.convertToInt(HeartBeatInterval.value) * 1000;
+    }
+    this.stationInfo?.autoRegister === false &&
+      logger.warn(
+        `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${
+          Constants.DEFAULT_HEARTBEAT_INTERVAL
+        }`
+      );
+    return Constants.DEFAULT_HEARTBEAT_INTERVAL;
+  }
+
   public setSupervisionUrl(url: string): void {
     if (
       this.getSupervisionUrlOcppConfiguration() &&
@@ -405,11 +428,7 @@ export class ChargingStation {
   }
 
   public startHeartbeat(): void {
-    if (
-      this.getHeartbeatInterval() &&
-      this.getHeartbeatInterval() > 0 &&
-      !this.heartbeatSetInterval
-    ) {
+    if (this.getHeartbeatInterval() > 0 && !this.heartbeatSetInterval) {
       this.heartbeatSetInterval = setInterval(() => {
         this.ocppRequestService
           .requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
@@ -433,11 +452,7 @@ export class ChargingStation {
       );
     } else {
       logger.error(
-        `${this.logPrefix()} Heartbeat interval set to ${
-          this.getHeartbeatInterval()
-            ? Utils.formatDurationMilliSeconds(this.getHeartbeatInterval())
-            : this.getHeartbeatInterval()
-        }, not starting the heartbeat`
+        `${this.logPrefix()} Heartbeat interval set to ${this.getHeartbeatInterval()}, not starting the heartbeat`
       );
     }
   }
@@ -642,7 +657,7 @@ export class ChargingStation {
   }
 
   public openWSConnection(
-    options: WsOptions = this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT,
+    options: WsOptions = this.stationInfo?.wsOptions ?? {},
     params: { closeOpened?: boolean; terminateOpened?: boolean } = {
       closeOpened: false,
       terminateOpened: false,
@@ -911,7 +926,7 @@ export class ChargingStation {
         },
         reset: true,
       },
-      stationTemplate?.firmwareUpgrade ?? Constants.EMPTY_OBJECT
+      stationTemplate?.firmwareUpgrade ?? {}
     );
     stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime)
       ? stationTemplate.resetTime * 1000
@@ -1377,7 +1392,7 @@ export class ChargingStation {
           fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
         }
         const configurationData: ChargingStationConfiguration =
-          Utils.cloneObject(this.getConfigurationFromFile()) ?? Constants.EMPTY_OBJECT;
+          Utils.cloneObject(this.getConfigurationFromFile()) ?? {};
         this.ocppConfiguration?.configurationKey &&
           (configurationData.configurationKey = this.ocppConfiguration.configurationKey);
         this.stationInfo && (configurationData.stationInfo = this.stationInfo);
@@ -1933,11 +1948,7 @@ export class ChargingStation {
       );
     } else {
       logger.error(
-        `${this.logPrefix()} WebSocket ping interval set to ${
-          webSocketPingInterval
-            ? Utils.formatDurationSeconds(webSocketPingInterval)
-            : webSocketPingInterval
-        }, not starting the WebSocket ping`
+        `${this.logPrefix()} WebSocket ping interval set to ${webSocketPingInterval}, not starting the WebSocket ping`
       );
     }
   }
@@ -1945,6 +1956,7 @@ export class ChargingStation {
   private stopWebSocketPing(): void {
     if (this.webSocketPingSetInterval) {
       clearInterval(this.webSocketPingSetInterval);
+      delete this.webSocketPingSetInterval;
     }
   }
 
@@ -1975,33 +1987,10 @@ export class ChargingStation {
     return new URL(supervisionUrls as string);
   }
 
-  private getHeartbeatInterval(): number {
-    const HeartbeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
-      this,
-      StandardParametersKey.HeartbeatInterval
-    );
-    if (HeartbeatInterval) {
-      return Utils.convertToInt(HeartbeatInterval.value) * 1000;
-    }
-    const HeartBeatInterval = ChargingStationConfigurationUtils.getConfigurationKey(
-      this,
-      StandardParametersKey.HeartBeatInterval
-    );
-    if (HeartBeatInterval) {
-      return Utils.convertToInt(HeartBeatInterval.value) * 1000;
-    }
-    this.stationInfo?.autoRegister === false &&
-      logger.warn(
-        `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${
-          Constants.DEFAULT_HEARTBEAT_INTERVAL
-        }`
-      );
-    return Constants.DEFAULT_HEARTBEAT_INTERVAL;
-  }
-
   private stopHeartbeat(): void {
     if (this.heartbeatSetInterval) {
       clearInterval(this.heartbeatSetInterval);
+      delete this.heartbeatSetInterval;
     }
   }
 
@@ -2056,7 +2045,7 @@ export class ChargingStation {
       );
       this.openWSConnection(
         {
-          ...(this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT),
+          ...(this.stationInfo?.wsOptions ?? {}),
           handshakeTimeout: reconnectTimeout,
         },
         { closeOpened: true }