From: Jérôme Benoit Date: Sun, 3 Jan 2021 00:41:41 +0000 (+0100) Subject: Untangle internal configuration key type from the OCPP one. X-Git-Tag: v1.0.1-0~152^2~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f7a1d1a9ec99a24e2a419895a9e7dd334af6f43a;p=e-mobility-charging-stations-simulator.git Untangle internal configuration key type from the OCPP one. Signed-off-by: Jérôme Benoit --- 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; +}