From: Jérôme Benoit Date: Fri, 28 Apr 2023 13:27:49 +0000 (+0200) Subject: feat: add connector status handling at boot with evses configuration X-Git-Tag: v1.2.12~53 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c3b8313087c651563b66173c2d6dd41034d194f9;p=e-mobility-charging-stations-simulator.git feat: add connector status handling at boot with evses configuration Reference: https://github.com/SAP/e-mobility-charging-stations-simulator/issues/349 Signed-off-by: Jérôme Benoit --- 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) {