From f7a1d1a9ec99a24e2a419895a9e7dd334af6f43a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 3 Jan 2021 01:41:41 +0100 Subject: [PATCH] Untangle internal configuration key type from the OCPP one. 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 | 9 +++++++-- src/types/ChargingStationConfiguration.ts | 7 ++----- src/types/ocpp/1.6/RequestResponses.ts | 4 ++-- src/types/ocpp/Configuration.ts | 7 +++++++ 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 src/types/ocpp/Configuration.ts diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d42a2daa..32289d60 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -20,6 +20,7 @@ import ElectricUtils from '../utils/ElectricUtils'; import { ErrorType } from '../types/ocpp/ErrorType'; import MeasurandValues from '../types/MeasurandValues'; import { MessageType } from '../types/ocpp/MessageType'; +import { OCPPConfigurationKey } from '../types/ocpp/Configuration'; import OCPPError from './OcppError'; import { StandardParametersKey } from '../types/ocpp/1.6/Configuration'; import Statistics from '../utils/Statistics'; @@ -1289,12 +1290,16 @@ export default class ChargingStation { } _getConfigurationKey(key: string | StandardParametersKey, caseInsensitive = false): ConfigurationKey { - return this._configuration.configurationKey.find((configElement) => { + const configurationKey: ConfigurationKey = this._configuration.configurationKey.find((configElement) => { if (caseInsensitive) { return configElement.key.toLowerCase() === key.toLowerCase(); } return configElement.key === key; }); + if (configurationKey && Utils.isUndefined(configurationKey.readonly)) { + configurationKey.readonly = false; + } + return configurationKey; } _addConfigurationKey(key: string | StandardParametersKey, value: string, readonly = false, visible = true, reboot = false): void { @@ -1319,7 +1324,7 @@ export default class ChargingStation { } handleRequestGetConfiguration(commandPayload: GetConfigurationRequest): GetConfigurationResponse { - const configurationKey: ConfigurationKey[] = []; + const configurationKey: OCPPConfigurationKey[] = []; const unknownKey: string[] = []; if (Utils.isEmptyArray(commandPayload.key)) { for (const configuration of this._configuration.configurationKey) { diff --git a/src/types/ChargingStationConfiguration.ts b/src/types/ChargingStationConfiguration.ts index 66d3e33a..7e0219fb 100644 --- a/src/types/ChargingStationConfiguration.ts +++ b/src/types/ChargingStationConfiguration.ts @@ -1,9 +1,6 @@ -import { StandardParametersKey } from './ocpp/1.6/Configuration'; +import { OCPPConfigurationKey } from './ocpp/Configuration'; -export interface ConfigurationKey { - key: string | StandardParametersKey; - readonly?: boolean; - value: string; +export interface ConfigurationKey extends OCPPConfigurationKey{ visible?: boolean; reboot?: boolean; } diff --git a/src/types/ocpp/1.6/RequestResponses.ts b/src/types/ocpp/1.6/RequestResponses.ts index b737ed97..79543d14 100644 --- a/src/types/ocpp/1.6/RequestResponses.ts +++ b/src/types/ocpp/1.6/RequestResponses.ts @@ -1,4 +1,4 @@ -import { ConfigurationKey } from '../../ChargingStationConfiguration'; +import { OCPPConfigurationKey } from '../Configuration'; export interface HeartbeatResponse { currentTime: string; @@ -50,7 +50,7 @@ export interface BootNotificationResponse { export interface StatusNotificationResponse { } export interface GetConfigurationResponse { - configurationKey: ConfigurationKey[]; + configurationKey: OCPPConfigurationKey[]; unknownKey: string[]; } diff --git a/src/types/ocpp/Configuration.ts b/src/types/ocpp/Configuration.ts new file mode 100644 index 00000000..57b3f90f --- /dev/null +++ b/src/types/ocpp/Configuration.ts @@ -0,0 +1,7 @@ +import { StandardParametersKey } from './1.6/Configuration'; + +export interface OCPPConfigurationKey { + key: string | StandardParametersKey; + readonly: boolean; + value?: string; +} -- 2.34.1