}
public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined {
+ const transactionConnectorStatus = this.getConnectorStatus(
+ this.getConnectorIdByTransactionId(transactionId)
+ );
if (this.getMeteringPerTransaction()) {
- for (const connectorId of this.connectors.keys()) {
- if (
- connectorId > 0 &&
- this.getConnectorStatus(connectorId).transactionId === transactionId
- ) {
- return this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue;
- }
- }
+ return transactionConnectorStatus.transactionEnergyActiveImportRegisterValue;
}
+ return transactionConnectorStatus.energyActiveImportRegisterValue;
+ }
+
+ public getConnectorIdByTransactionId(transactionId: number): number | undefined {
for (const connectorId of this.connectors.keys()) {
- if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionId === transactionId) {
- return this.getConnectorStatus(connectorId).energyActiveImportRegisterValue;
+ if (
+ connectorId > 0 &&
+ this.getConnectorStatus(connectorId)?.transactionId === transactionId
+ ) {
+ return connectorId;
}
}
}
timestamp: new Date().toISOString(),
} as StartTransactionRequest;
case OCPP16RequestCommand.STOP_TRANSACTION:
- for (const id of this.chargingStation.connectors.keys()) {
- if (
- id > 0 &&
- this.chargingStation.getConnectorStatus(id)?.transactionId ===
- commandParams?.transactionId
- ) {
- connectorId = id;
- break;
- }
- }
+ connectorId = this.chargingStation.getConnectorIdByTransactionId(
+ commandParams?.transactionId as number
+ );
return {
transactionId: commandParams?.transactionId,
...(!Utils.isUndefined(commandParams?.idTag) && { idTag: commandParams.idTag }),
payload: OCPP16StopTransactionResponse,
requestPayload: StopTransactionRequest
): Promise<void> {
- let transactionConnectorId: number;
- for (const connectorId of this.chargingStation.connectors.keys()) {
- if (
- connectorId > 0 &&
- this.chargingStation.getConnectorStatus(connectorId)?.transactionId ===
- requestPayload.transactionId
- ) {
- transactionConnectorId = connectorId;
- break;
- }
- }
+ const transactionConnectorId = this.chargingStation.getConnectorIdByTransactionId(
+ requestPayload.transactionId
+ );
if (!transactionConnectorId) {
logger.error(
this.chargingStation.logPrefix() +