From: Jérôme Benoit Date: Wed, 18 Mar 2026 14:35:41 +0000 (+0100) Subject: fix(ocpp2): revert UI transaction handlers to simple passthrough X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7b543d0cd334e0ddb350bc1311731f1732de4116;p=e-mobility-charging-stations-simulator.git fix(ocpp2): revert UI transaction handlers to simple passthrough Remove handleUIStartTransaction and handleUIStopTransaction which duplicated connector state management with incomplete initialization (missing energy register, groupIdToken, StatusNotification, error rollback) and bypassed authorization checks. Restore handleTransactionEvent as a simple requestHandler passthrough, consistent with all other broadcast channel command handlers. --- diff --git a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts index 8b818c58..ba414170 100644 --- a/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts @@ -19,7 +19,6 @@ import { type DiagnosticsStatusNotificationRequest, type DiagnosticsStatusNotificationResponse, type EmptyObject, - ErrorType, type FirmwareStatusNotificationRequest, type FirmwareStatusNotificationResponse, GenericStatus, @@ -45,10 +44,8 @@ import { type OCPP20SecurityEventNotificationResponse, type OCPP20SignCertificateRequest, type OCPP20SignCertificateResponse, - OCPP20TransactionEventEnumType, type OCPP20TransactionEventRequest, type OCPP20TransactionEventResponse, - OCPP20TriggerReasonEnumType, OCPPVersion, RegistrationStatusEnumType, RequestCommand, @@ -65,14 +62,13 @@ import { import { Constants, convertToInt, - generateUUID, getErrorMessage, isAsyncFunction, isEmpty, logger, } from '../../utils/index.js' import { getConfigurationKey } from '../ConfigurationKeyUtils.js' -import { buildMeterValue, OCPP20ServiceUtils } from '../ocpp/index.js' +import { buildMeterValue } from '../ocpp/index.js' import { WorkerBroadcastChannel } from './WorkerBroadcastChannel.js' const moduleName = 'ChargingStationWorkerBroadcastChannel' @@ -623,66 +619,15 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne private async handleTransactionEvent ( requestPayload?: BroadcastChannelRequestPayload ): Promise { - const payload = requestPayload as OCPP20TransactionEventRequest - - switch (payload.eventType) { - case OCPP20TransactionEventEnumType.Ended: - return this.handleUIStopTransaction(payload) - case OCPP20TransactionEventEnumType.Started: - return this.handleUIStartTransaction(payload) - default: - return await this.chargingStation.ocppRequestService.requestHandler< - OCPP20TransactionEventRequest, - OCPP20TransactionEventResponse - >(this.chargingStation, RequestCommand.TRANSACTION_EVENT, payload, this.requestParams) - } - } - - private async handleUIStartTransaction ( - payload: OCPP20TransactionEventRequest - ): Promise { - const connectorId = payload.evse?.connectorId ?? payload.evse?.id ?? 1 - const transactionId = generateUUID() - - const connectorStatus = this.chargingStation.getConnectorStatus(connectorId) - if (connectorStatus != null) { - connectorStatus.transactionStarted = true - connectorStatus.transactionId = transactionId - connectorStatus.transactionIdTag = payload.idToken?.idToken - connectorStatus.transactionStart = new Date() - } - - const response = await OCPP20ServiceUtils.sendTransactionEvent( + return await this.chargingStation.ocppRequestService.requestHandler< + OCPP20TransactionEventRequest, + OCPP20TransactionEventResponse + >( this.chargingStation, - OCPP20TransactionEventEnumType.Started, - OCPP20TriggerReasonEnumType.Authorized, - connectorId, - transactionId + RequestCommand.TRANSACTION_EVENT, + requestPayload as OCPP20TransactionEventRequest, + this.requestParams ) - - const txUpdatedInterval = OCPP20ServiceUtils.getTxUpdatedInterval(this.chargingStation) - this.chargingStation.startTxUpdatedInterval(connectorId, txUpdatedInterval) - - return response - } - - private async handleUIStopTransaction ( - payload: OCPP20TransactionEventRequest - ): Promise { - const transactionId = (payload as unknown as { transactionId?: string }).transactionId - if (transactionId == null) { - throw new OCPPError(ErrorType.PROPERTY_CONSTRAINT_VIOLATION, 'Missing transactionId for stop') - } - - const connectorId = this.chargingStation.getConnectorIdByTransactionId(transactionId) - if (connectorId == null) { - throw new OCPPError( - ErrorType.PROPERTY_CONSTRAINT_VIOLATION, - `No connector found for transaction ${transactionId}` - ) - } - - return await OCPP20ServiceUtils.requestStopTransaction(this.chargingStation, connectorId) } private messageErrorHandler (messageEvent: MessageEvent): void {