From e6895390a1697376fdee9c7ebb1e775c24f1022d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 12 Mar 2022 12:32:56 +0100 Subject: [PATCH] Delete supervision url configuration key if the feature is disabled from persistent storage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 3000d6d0..01829fdf 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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( -- 2.34.1