Handle connectors number shrinking at template reload.
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 29 Sep 2021 03:28:41 +0000 (05:28 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 29 Sep 2021 03:28:41 +0000 (05:28 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/ChargingStation.ts

index f93f4133bccfbd68cda6297284f4f22a96b418fe..a5319eccbf93b1ab8f5c4c634a72e46cd0ea70e6 100644 (file)
@@ -508,8 +508,9 @@ export default class ChargingStation {
       this.stationInfo.randomConnectors = true;
     }
     const connectorsConfigHash = crypto.createHash('sha256').update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.toString()).digest('hex');
-    // FIXME: Handle shrinking the number of connectors
-    if (!this.connectors || (this.connectors && this.connectorsConfigurationHash !== connectorsConfigHash)) {
+    const connectorsConfigChanged = !Utils.isEmptyObject(this.connectors) && this.connectorsConfigurationHash !== connectorsConfigHash;
+    if (Utils.isEmptyObject(this.connectors) || connectorsConfigChanged) {
+      connectorsConfigChanged && (this.connectors = {} as Connectors);
       this.connectorsConfigurationHash = connectorsConfigHash;
       // Add connector Id 0
       let lastConnector = '0';