From c3b8313087c651563b66173c2d6dd41034d194f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 28 Apr 2023 15:27:49 +0200 Subject: [PATCH] feat: add connector status handling at boot with evses configuration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reference: https://github.com/SAP/e-mobility-charging-stations-simulator/issues/349 Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 48 ++++++++++---------- src/charging-station/ChargingStationUtils.ts | 26 +++++++++++ 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 70f511e0..c51064f6 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1997,30 +1997,32 @@ export class ChargingStation { // Start heartbeat this.startHeartbeat(); // Initialize connectors status - for (const connectorId of this.connectors.keys()) { - let connectorStatus: ConnectorStatusEnum | undefined; - if (connectorId === 0) { - continue; - } else if ( - !this.getConnectorStatus(connectorId)?.status && - (this.isChargingStationAvailable() === false || - this.isConnectorAvailable(connectorId) === false) - ) { - connectorStatus = ConnectorStatusEnum.Unavailable; - } else if ( - !this.getConnectorStatus(connectorId)?.status && - this.getConnectorStatus(connectorId)?.bootStatus - ) { - // Set boot status in template at startup - connectorStatus = this.getConnectorStatus(connectorId)?.bootStatus; - } else if (this.getConnectorStatus(connectorId)?.status) { - // Set previous status at startup - connectorStatus = this.getConnectorStatus(connectorId)?.status; - } else { - // Set default status - connectorStatus = ConnectorStatusEnum.Available; + if (this.hasEvses) { + for (const [evseId, evseStatus] of this.evses) { + if (evseId === 0) { + continue; + } + for (const [connectorId, connectorStatus] of evseStatus.connectors) { + const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus( + this, + connectorId, + connectorStatus + ); + await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorBootStatus); + } + } + } else { + for (const connectorId of this.connectors.keys()) { + if (connectorId === 0) { + continue; + } + const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus( + this, + connectorId, + this.getConnectorStatus(connectorId) + ); + await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorBootStatus); } - await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorStatus); } if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) { await this.ocppRequestService.requestHandler< diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 49a61101..4564f389 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -19,6 +19,7 @@ import { type ChargingStationInfo, type ChargingStationTemplate, type ConnectorStatus, + ConnectorStatusEnum, CurrentType, type EvseTemplate, type OCPP16BootNotificationRequest, @@ -125,6 +126,31 @@ export class ChargingStationUtils { } } + public static getBootConnectorStatus( + chargingStation: ChargingStation, + connectorId: number, + connectorStatus: ConnectorStatus + ): ConnectorStatusEnum { + let connectorBootStatus: ConnectorStatusEnum; + if ( + !connectorStatus?.status && + (chargingStation.isChargingStationAvailable() === false || + chargingStation.isConnectorAvailable(connectorId) === false) + ) { + connectorBootStatus = ConnectorStatusEnum.Unavailable; + } else if (!connectorStatus?.status && connectorStatus?.bootStatus) { + // Set boot status in template at startup + connectorBootStatus = connectorStatus?.bootStatus; + } else if (connectorStatus?.status) { + // Set previous status at startup + connectorBootStatus = connectorStatus?.status; + } else { + // Set default status + connectorBootStatus = ConnectorStatusEnum.Available; + } + return connectorBootStatus; + } + public static getConfiguredNumberOfConnectors(stationInfo: ChargingStationInfo): number { let configuredMaxConnectors: number; if (Utils.isNotEmptyArray(stationInfo.numberOfConnectors) === true) { -- 2.34.1