UI Server: Cleanup commands handling initialization
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Oct 2022 19:44:59 +0000 (21:44 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Oct 2022 19:44:59 +0000 (21:44 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/charging-station/ui-server/ui-services/UIService001.ts

index 7078641b8837edfa55e13495b108dd0473c4de6f..40b846217556023b671d8f31a0f5d7996cc2bd0c 100644 (file)
@@ -536,7 +536,6 @@ export default class ChargingStation {
         this.stopping = true;
         await this.stopMessageSequence(reason);
         this.closeWSConnection();
-        this.wsConnectionRestarted = false;
         if (this.getEnableStatistics()) {
           this.performanceStatistics.stop();
         }
@@ -1855,9 +1854,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 +1978,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 +1994,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()})`
       );
     }
   }
index 729b816dd15c2c9d1ee8a0215480601365f598d7..e26a69be201d50981b42fa0488d5edd375c371b6 100644 (file)
@@ -22,7 +22,7 @@ import type { AbstractUIServer } from '../AbstractUIServer';
 const moduleName = 'AbstractUIService';
 
 export default abstract class AbstractUIService {
-  private static readonly ProcedureNameToBroadCastChannelProcedureNameMap: Omit<
+  protected static readonly ProcedureNameToBroadCastChannelProcedureNameMap: Omit<
     Record<ProcedureName, BroadcastChannelProcedureName>,
     | ProcedureName.START_SIMULATOR
     | ProcedureName.STOP_SIMULATOR
index b02bac82cbb029e654e35e69769c45080a4a0fd2..de7ba25736e60c6ebbc036d44259550cd7eb74b2 100644 (file)
@@ -9,57 +9,13 @@ import AbstractUIService from './AbstractUIService';
 export default class UIService001 extends AbstractUIService {
   constructor(uiServer: AbstractUIServer) {
     super(uiServer, ProtocolVersion['0.0.1']);
-    this.requestHandlers.set(
-      ProcedureName.START_CHARGING_STATION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.STOP_CHARGING_STATION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.OPEN_CONNECTION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.CLOSE_CONNECTION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.START_TRANSACTION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.STOP_TRANSACTION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.AUTHORIZE,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.BOOT_NOTIFICATION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.STATUS_NOTIFICATION,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.HEARTBEAT,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
-    this.requestHandlers.set(
-      ProcedureName.METER_VALUES,
-      this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
-    );
+    for (const procedureName of Object.keys(
+      AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMap
+    ) as ProcedureName[]) {
+      this.requestHandlers.set(
+        procedureName,
+        this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
+      );
+    }
   }
 }