Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Ensure connector status is defined before getting its attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Mar 9, 2022
1 parent ef2d006 commit cbad121
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down

0 comments on commit cbad121

Please sign in to comment.