From: Jérôme Benoit Date: Thu, 30 Sep 2021 20:15:02 +0000 (+0200) Subject: Reset ATG connectors status if the number of connectors have changed X-Git-Tag: v1.1.20~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=54544ef1ca864c3a2e07ff020a7b8f0b38a825fd;p=e-mobility-charging-stations-simulator.git Reset ATG connectors status if the number of connectors have changed Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 877339c2..6913853b 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -40,6 +40,9 @@ export default class AutomaticTransactionGenerator { } private startConnectors(): void { + if (this.connectorsStatus?.size !== 0 && this.connectorsStatus.size !== this.chargingStation.getNumberOfConnectors()) { + this.connectorsStatus.clear(); + } for (const connectorId of this.chargingStation.connectors.keys()) { if (connectorId > 0) { this.startConnector(connectorId); diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6900cdc3..a01beda2 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -126,6 +126,10 @@ export default class ChargingStation { return this.getConnectorStatus(id).availability === AvailabilityType.OPERATIVE; } + public getNumberOfConnectors(): number { + return this.connectors.get(0) ? this.connectors.size - 1 : this.connectors.size; + } + public getConnectorStatus(id: number): ConnectorStatus { return this.connectors.get(id); } @@ -508,8 +512,8 @@ export default class ChargingStation { this.stationInfo.randomConnectors = true; } const connectorsConfigHash = crypto.createHash('sha256').update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.toString()).digest('hex'); - const connectorsConfigChanged = this.connectors.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash; - if (!this.connectors || this.connectors.size === 0 || connectorsConfigChanged) { + const connectorsConfigChanged = this.connectors?.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash; + if (this.connectors?.size === 0 || connectorsConfigChanged) { connectorsConfigChanged && (this.connectors.clear()); this.connectorsConfigurationHash = connectorsConfigHash; // Add connector Id 0 @@ -827,10 +831,6 @@ export default class ChargingStation { return maxConnectors; } - private getNumberOfConnectors(): number { - return this.connectors.get(0) ? this.connectors.size - 1 : this.connectors.size; - } - private async startMessageSequence(): Promise { // Start WebSocket ping this.startWebSocketPing();