From: Jérôme Benoit Date: Mon, 16 Mar 2026 16:28:14 +0000 (+0100) Subject: refactor(ocpp20): move TransactionEvent(Started) to event listener pattern X-Git-Tag: ocpp-server@v3.1.1~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=65f9d786bc46a274e1cb59edb9194bb87617ec65;p=e-mobility-charging-stations-simulator.git refactor(ocpp20): move TransactionEvent(Started) to event listener pattern Move sendTransactionEvent(Started) and startTxUpdatedInterval from inside handleRequestStartTransaction to a post-response event listener in the constructor, matching the OCPP 1.6 RemoteStartTransaction pattern where the handler validates and returns Accepted, then an event triggers the actual StartTransaction message send. --- diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 018a03e1..e6ce847f 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -340,6 +340,36 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { } } ) + // E02.FR.01: Send TransactionEvent(Started) after accepting remote start + this.on( + OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION, + ( + chargingStation: ChargingStation, + request: OCPP20RequestStartTransactionRequest, + response: OCPP20RequestStartTransactionResponse + ) => { + if (response.status === RequestStartStopStatusEnumType.Accepted) { + const connectorId = chargingStation.getConnectorIdByTransactionId(response.transactionId) + if (connectorId != null) { + OCPP20ServiceUtils.sendTransactionEvent( + chargingStation, + OCPP20TransactionEventEnumType.Started, + OCPP20TriggerReasonEnumType.RemoteStart, + connectorId, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + response.transactionId! + ).catch((error: unknown) => { + logger.error( + `${chargingStation.logPrefix()} ${moduleName}.constructor: TransactionEvent(Started) error:`, + error + ) + }) + const txUpdatedInterval = this.getTxUpdatedInterval(chargingStation) + chargingStation.startTxUpdatedInterval(connectorId, txUpdatedInterval) + } + } + } + ) this.on( OCPP20IncomingRequestCommand.TRIGGER_MESSAGE, ( @@ -2461,18 +2491,6 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { evseId ) - // E02.FR.01: Send TransactionEvent(Started) to CSMS - await OCPP20ServiceUtils.sendTransactionEvent( - chargingStation, - OCPP20TransactionEventEnumType.Started, - OCPP20TriggerReasonEnumType.RemoteStart, - connectorId, - transactionId - ) - - const txUpdatedInterval = this.getTxUpdatedInterval(chargingStation) - chargingStation.startTxUpdatedInterval(connectorId, txUpdatedInterval) - if (chargingProfile != null) { connectorStatus.chargingProfiles ??= [] connectorStatus.chargingProfiles.push(chargingProfile)