Delete supervision url configuration key if the feature is disabled from
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 12 Mar 2022 11:32:56 +0000 (12:32 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 12 Mar 2022 11:32:56 +0000 (12:32 +0100)
persistent storage

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 3000d6d08533c32dc4b23b8ac198acdd51ab72e1..01829fdf47273797aefa980824db13282cd72862 100644 (file)
@@ -633,10 +633,7 @@ export default class ChargingStation {
     const reboot = options.reboot;
     let keyFound = this.getConfigurationKey(key);
     if (keyFound && params?.overwrite) {
-      this.configuration.configurationKey.splice(
-        this.configuration.configurationKey.indexOf(keyFound),
-        1
-      );
+      this.deleteConfigurationKey(keyFound.key, { save: false });
       keyFound = undefined;
     }
     if (!keyFound) {
@@ -674,6 +671,21 @@ export default class ChargingStation {
     }
   }
 
+  public deleteConfigurationKey(
+    key: string | StandardParametersKey,
+    params: { save?: boolean; caseInsensitive?: boolean } = { save: true, caseInsensitive: false }
+  ): ConfigurationKey[] {
+    const keyFound = this.getConfigurationKey(key, params?.caseInsensitive);
+    if (keyFound) {
+      const deletedConfigurationKey = this.configuration.configurationKey.splice(
+        this.configuration.configurationKey.indexOf(keyFound),
+        1
+      );
+      params?.save && this.saveConfiguration();
+      return deletedConfigurationKey;
+    }
+  }
+
   public setChargingProfile(connectorId: number, cp: ChargingProfile): void {
     let cpReplaced = false;
     if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
@@ -966,6 +978,11 @@ export default class ChargingStation {
         this.getConfiguredSupervisionUrl().href,
         { reboot: true }
       );
+    } else if (
+      !this.getSupervisionUrlOcppConfiguration() &&
+      this.getConfigurationKey(this.getSupervisionUrlOcppKey())
+    ) {
+      this.deleteConfigurationKey(this.getSupervisionUrlOcppKey(), { save: false });
     }
     if (!this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)) {
       this.addConfigurationKey(