Reset ATG connectors status if the number of connectors have changed
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Sep 2021 20:15:02 +0000 (22:15 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Sep 2021 20:15:02 +0000 (22:15 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts

index 877339c2da8069e1a9fa5db799bffb0b864d1642..6913853b2911b8354784d9799f9d377c8356aa2d 100644 (file)
@@ -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);
index 6900cdc3c67e2ec9a1d83da627fa99262d39c525..a01beda2acf802ba794c818277b71abc8e408f0b 100644 (file)
@@ -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<void> {
     // Start WebSocket ping
     this.startWebSocketPing();