From: Jérôme Benoit Date: Wed, 9 Mar 2022 22:06:39 +0000 (+0100) Subject: Ensure connector status is defined before getting its attributes X-Git-Tag: v1.1.54~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cbad1217b743f0a06653689fb9c1344ac2194348;p=e-mobility-charging-stations-simulator.git Ensure connector status is defined before getting its attributes Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 36c5b8d5..a451c5ee 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -255,16 +255,6 @@ export default class ChargingStation { return this.stationInfo.phaseLineToLineVoltageMeterValues ?? false; } - public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined { - const transactionConnectorStatus = this.getConnectorStatus( - this.getConnectorIdByTransactionId(transactionId) - ); - if (this.getMeteringPerTransaction()) { - return transactionConnectorStatus.transactionEnergyActiveImportRegisterValue; - } - return transactionConnectorStatus.energyActiveImportRegisterValue; - } - public getConnectorIdByTransactionId(transactionId: number): number | undefined { for (const connectorId of this.connectors.keys()) { if ( @@ -276,11 +266,22 @@ export default class ChargingStation { } } + public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined { + const transactionConnectorStatus = this.getConnectorStatus( + this.getConnectorIdByTransactionId(transactionId) + ); + if (this.getMeteringPerTransaction()) { + return transactionConnectorStatus?.transactionEnergyActiveImportRegisterValue; + } + return transactionConnectorStatus?.energyActiveImportRegisterValue; + } + public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number | undefined { + const connectorStatus = this.getConnectorStatus(connectorId); if (this.getMeteringPerTransaction()) { - return this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue; + return connectorStatus?.transactionEnergyActiveImportRegisterValue; } - return this.getConnectorStatus(connectorId).energyActiveImportRegisterValue; + return connectorStatus?.energyActiveImportRegisterValue; } public getAuthorizeRemoteTxRequests(): boolean {