- public getConfigurationKey(
- key: string | StandardParametersKey,
- caseInsensitive = false
- ): ConfigurationKey | undefined {
- return this.ocppConfiguration.configurationKey.find((configElement) => {
- if (caseInsensitive) {
- return configElement.key.toLowerCase() === key.toLowerCase();
- }
- return configElement.key === key;
- });
- }
-
- public addConfigurationKey(
- key: string | StandardParametersKey,
- value: string,
- options: { readonly?: boolean; visible?: boolean; reboot?: boolean } = {
- readonly: false,
- visible: true,
- reboot: false,
- },
- params: { overwrite?: boolean; save?: boolean } = { overwrite: false, save: false }
- ): void {
- options = options ?? ({} as { readonly?: boolean; visible?: boolean; reboot?: boolean });
- options.readonly = options?.readonly ?? false;
- options.visible = options?.visible ?? true;
- options.reboot = options?.reboot ?? false;
- let keyFound = this.getConfigurationKey(key);
- if (keyFound && params?.overwrite) {
- this.deleteConfigurationKey(keyFound.key, { save: false });
- keyFound = undefined;
- }
- if (!keyFound) {
- this.ocppConfiguration.configurationKey.push({
- key,
- readonly: options.readonly,
- value,
- visible: options.visible,
- reboot: options.reboot,
- });
- params?.save && this.saveOcppConfiguration();
- } else {
- logger.error(
- `${this.logPrefix()} Trying to add an already existing configuration key: %j`,
- keyFound
- );
- }
- }
-
- public setConfigurationKeyValue(
- key: string | StandardParametersKey,
- value: string,
- caseInsensitive = false
- ): void {
- const keyFound = this.getConfigurationKey(key, caseInsensitive);
- if (keyFound) {
- this.ocppConfiguration.configurationKey[
- this.ocppConfiguration.configurationKey.indexOf(keyFound)
- ].value = value;
- this.saveOcppConfiguration();
- } else {
- logger.error(
- `${this.logPrefix()} Trying to set a value on a non existing configuration key: %j`,
- { key, value }
- );
- }
- }
-
- 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.ocppConfiguration.configurationKey.splice(
- this.ocppConfiguration.configurationKey.indexOf(keyFound),
- 1
- );
- params?.save && this.saveOcppConfiguration();
- return deletedConfigurationKey;