From cbad1217b743f0a06653689fb9c1344ac2194348 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 9 Mar 2022 23:06:39 +0100 Subject: [PATCH] Ensure connector status is defined before getting its attributes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) 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 { -- 2.34.1