eslint: report missed TS rules in the shared rules
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 7078641b8837edfa55e13495b108dd0473c4de6f..85a62c589d2549e96fd86249cf3fa0e72e80aef0 100644 (file)
@@ -216,7 +216,10 @@ export default class ChargingStation {
   }
 
   public isRegistered(): boolean {
-    return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState());
+    return (
+      this.isInUnknownState() === false &&
+      (this.isInAcceptedState() === true || this.isInPendingState() === true)
+    );
   }
 
   public isChargingStationAvailable(): boolean {
@@ -536,7 +539,6 @@ export default class ChargingStation {
         this.stopping = true;
         await this.stopMessageSequence(reason);
         this.closeWSConnection();
-        this.wsConnectionRestarted = false;
         if (this.getEnableStatistics()) {
           this.performanceStatistics.stop();
         }
@@ -705,9 +707,9 @@ export default class ChargingStation {
   ): Promise<StopTransactionResponse> {
     const transactionId = this.getConnectorStatus(connectorId).transactionId;
     if (
-      this.getBeginEndMeterValues() &&
-      this.getOcppStrictCompliance() &&
-      !this.getOutOfOrderEndMeterValues()
+      this.getBeginEndMeterValues() === true &&
+      this.getOcppStrictCompliance() === true &&
+      this.getOutOfOrderEndMeterValues() === false
     ) {
       // FIXME: Implement OCPP version agnostic helpers
       const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
@@ -1197,10 +1199,17 @@ export default class ChargingStation {
     }
     // Initialize transaction attributes on connectors
     for (const connectorId of this.connectors.keys()) {
+      if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionStarted === true) {
+        logger.warn(
+          `${this.logPrefix()} Connector ${connectorId} at initialization has a transaction started: ${
+            this.getConnectorStatus(connectorId).transactionId
+          }`
+        );
+      }
       if (
         connectorId > 0 &&
         (this.getConnectorStatus(connectorId).transactionStarted === undefined ||
-          this.getConnectorStatus(connectorId).transactionStarted === false)
+          this.getConnectorStatus(connectorId).transactionStarted === null)
       ) {
         this.initializeConnectorStatus(connectorId);
       }
@@ -1327,7 +1336,7 @@ export default class ChargingStation {
       logger.info(
         `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`
       );
-      if (!this.isRegistered()) {
+      if (this.isRegistered() === false) {
         // Send BootNotification
         let registrationRetryCount = 0;
         do {
@@ -1337,7 +1346,7 @@ export default class ChargingStation {
           >(this, RequestCommand.BOOT_NOTIFICATION, this.bootNotificationRequest, {
             skipBufferingOnError: true,
           });
-          if (!this.isRegistered()) {
+          if (this.isRegistered() === false) {
             this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
             await Utils.sleep(
               this.bootNotificationResponse?.interval
@@ -1346,12 +1355,12 @@ export default class ChargingStation {
             );
           }
         } while (
-          !this.isRegistered() &&
+          this.isRegistered() === false &&
           (registrationRetryCount <= this.getRegistrationMaxRetries() ||
             this.getRegistrationMaxRetries() === -1)
         );
       }
-      if (this.isRegistered()) {
+      if (this.isRegistered() === true) {
         if (this.isInAcceptedState()) {
           await this.startMessageSequence();
         }
@@ -1765,8 +1774,7 @@ export default class ChargingStation {
       } else if (
         !this.getConnectorStatus(connectorId)?.status &&
         (this.isChargingStationAvailable() === false ||
-          (this.isChargingStationAvailable() === true &&
-            this.isConnectorAvailable(connectorId) === false))
+          this.isConnectorAvailable(connectorId) === false)
       ) {
         chargePointStatus = ChargePointStatus.UNAVAILABLE;
       } else if (
@@ -1842,9 +1850,7 @@ export default class ChargingStation {
     if (webSocketPingInterval > 0 && !this.webSocketPingSetInterval) {
       this.webSocketPingSetInterval = setInterval(() => {
         if (this.isWebSocketConnectionOpened() === true) {
-          this.wsConnection.ping((): void => {
-            /* This is intentional */
-          });
+          this.wsConnection.ping();
         }
       }, webSocketPingInterval * 1000);
       logger.info(
@@ -1855,9 +1861,8 @@ export default class ChargingStation {
     } else if (this.webSocketPingSetInterval) {
       logger.info(
         this.logPrefix() +
-          ' WebSocket ping every ' +
-          Utils.formatDurationSeconds(webSocketPingInterval) +
-          ' already started'
+          ' WebSocket ping already started every ' +
+          Utils.formatDurationSeconds(webSocketPingInterval)
       );
     } else {
       logger.error(
@@ -1980,16 +1985,14 @@ export default class ChargingStation {
           ? reconnectDelay - reconnectDelayWithdraw
           : 0;
       logger.error(
-        `${this.logPrefix()} WebSocket: connection retry in ${Utils.roundTo(
+        `${this.logPrefix()} WebSocket connection retry in ${Utils.roundTo(
           reconnectDelay,
           2
         )}ms, timeout ${reconnectTimeout}ms`
       );
       await Utils.sleep(reconnectDelay);
       logger.error(
-        this.logPrefix() +
-          ' WebSocket: reconnecting try #' +
-          this.autoReconnectRetryCount.toString()
+        this.logPrefix() + ' WebSocket connection retry #' + this.autoReconnectRetryCount.toString()
       );
       this.openWSConnection(
         { ...(this.stationInfo?.wsOptions ?? {}), handshakeTimeout: reconnectTimeout },
@@ -1998,9 +2001,9 @@ export default class ChargingStation {
       this.wsConnectionRestarted = true;
     } else if (this.getAutoReconnectMaxRetries() !== -1) {
       logger.error(
-        `${this.logPrefix()} WebSocket reconnect failure: maximum retries reached (${
+        `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${
           this.autoReconnectRetryCount
-        }) or retry disabled (${this.getAutoReconnectMaxRetries()})`
+        }) or retries disabled (${this.getAutoReconnectMaxRetries()})`
       );
     }
   }