From: Jérôme Benoit Date: Mon, 5 Sep 2022 01:25:15 +0000 (+0200) Subject: Simplify stop transaction payload handling X-Git-Tag: v1.1.71~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cf058664a0053a43b9ac08815b6e430179ff5ddf;p=e-mobility-charging-stations-simulator.git Simplify stop transaction payload handling Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b6628cd7..bbe294b6 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -750,7 +750,6 @@ export default class ChargingStation { { transactionId, meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId, true), - idTag: this.getTransactionIdTag(transactionId), reason, } ); diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index ebc10099..dfb50ab1 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -142,8 +142,8 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca requestPayload.transactionId, true ), - idTag: this.chargingStation.getTransactionIdTag(requestPayload.transactionId), - ...(requestPayload.reason && { reason: requestPayload.reason }), + idTag: requestPayload.idTag, + reason: requestPayload.reason, }); case BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR: this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds); diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index 7e4cc877..650a8b9e 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -58,7 +58,7 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan private buildResponsePayload(uuid: string): ResponsePayload { const responsesStatus = this.responses .get(uuid) - ?.responses.every((response) => response.status === ResponseStatus.SUCCESS) + ?.responses.every(({ status }) => status === ResponseStatus.SUCCESS) ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE; return { diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 4fa0190e..fef9d86d 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -179,6 +179,7 @@ export default class OCPP16RequestService extends OCPPRequestService { commandParams?: JsonType ): Request { let connectorId: number; + let energyActiveImportRegister: number; commandParams = commandParams as JsonObject; switch (commandName) { case OCPP16RequestCommand.AUTHORIZE: @@ -242,19 +243,25 @@ export default class OCPP16RequestService extends OCPPRequestService { connectorId = chargingStation.getConnectorIdByTransactionId( commandParams?.transactionId as number ); + energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId( + commandParams?.transactionId as number, + true + ); return { transactionId: commandParams?.transactionId, - ...(!Utils.isUndefined(commandParams?.idTag) && { idTag: commandParams.idTag }), - meterStop: commandParams?.meterStop, + idTag: + commandParams?.idTag ?? + chargingStation.getTransactionIdTag(commandParams?.transactionId as number), + meterStop: commandParams?.meterStop ?? energyActiveImportRegister, timestamp: new Date().toISOString(), - ...(commandParams?.reason && { reason: commandParams.reason }), + reason: commandParams?.reason, ...(chargingStation.getTransactionDataMeterValues() && { transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues( chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue, OCPP16ServiceUtils.buildTransactionEndMeterValue( chargingStation, connectorId, - commandParams?.meterStop as number + (commandParams?.meterStop as number) ?? energyActiveImportRegister ) ), }), diff --git a/src/types/ocpp/1.6/Transaction.ts b/src/types/ocpp/1.6/Transaction.ts index ca68117d..14f9223c 100644 --- a/src/types/ocpp/1.6/Transaction.ts +++ b/src/types/ocpp/1.6/Transaction.ts @@ -42,8 +42,8 @@ export interface OCPP16StartTransactionRequest extends JsonObject { connectorId: number; idTag: string; meterStart: number; - reservationId?: number; timestamp: string; + reservationId?: number; } export interface OCPP16StartTransactionResponse extends JsonObject {