From: Jérôme Benoit Date: Sun, 2 Oct 2022 19:44:59 +0000 (+0200) Subject: UI Server: Cleanup commands handling initialization X-Git-Tag: v1.1.75~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d56ea27cd1c2e1df9317602551c443a720e1c7cb;p=e-mobility-charging-stations-simulator.git UI Server: Cleanup commands handling initialization Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7078641b..40b84621 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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()})` ); } } diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 729b816d..e26a69be 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -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.START_SIMULATOR | ProcedureName.STOP_SIMULATOR diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index b02bac82..de7ba257 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -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 + ); + } } }