get wsConnectionUrl(): URL {
return this.getSupervisionUrlOcppConfiguration()
? new URL(
- this.getConfigurationKey(
- this.stationInfo.supervisionUrlOcppKey ?? VendorDefaultParametersKey.ConnectionUrl
- ).value +
+ this.getConfigurationKey(this.getSupervisionUrlOcppKey()).value +
'/' +
this.stationInfo.chargingStationId
)
}
}
);
- FileUtils.watchJsonFile<ChargingStationConfiguration>(
- this.logPrefix(),
- FileType.ChargingStationConfiguration,
- this.configurationFile,
- this.configuration
- );
+ // FIXME: triggered by saveConfiguration()
+ // if (this.getOcppPersistentConfiguration()) {
+ // FileUtils.watchJsonFile<ChargingStationConfiguration>(
+ // this.logPrefix(),
+ // FileType.ChargingStationConfiguration,
+ // this.configurationFile,
+ // this.configuration
+ // );
+ // }
// Handle WebSocket message
this.wsConnection.on(
'message',
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) {
}
}
+ 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)) {
return this.stationInfo.supervisionUrlOcppConfiguration ?? false;
}
+ private getSupervisionUrlOcppKey(): string {
+ return this.stationInfo.supervisionUrlOcppKey ?? VendorDefaultParametersKey.ConnectionUrl;
+ }
+
private getChargingStationId(stationTemplate: ChargingStationTemplate): string {
// In case of multiple instances: add instance index to charging station id
const instanceIndex = process.env.CF_INSTANCE_INDEX ?? 0;
return this.stationInfo.ocppVersion ? this.stationInfo.ocppVersion : OCPPVersion.VERSION_16;
}
+ private getOcppPersistentConfiguration(): boolean {
+ return this.stationInfo.ocppPersistentConfiguration ?? true;
+ }
+
private handleUnsupportedVersion(version: OCPPVersion) {
const errMsg = `${this.logPrefix()} Unsupported protocol version '${version}' configured in template file ${
this.stationTemplateFile
this.stationInfo = this.buildStationInfo();
this.configurationFile = path.join(
path.resolve(__dirname, '../'),
- 'assets',
- 'configurations',
+ 'assets/configurations',
this.stationInfo.chargingStationId + '.json'
);
this.configuration = this.getConfiguration();
private initOcppParameters(): void {
if (
this.getSupervisionUrlOcppConfiguration() &&
- !this.getConfigurationKey(
- this.stationInfo.supervisionUrlOcppKey ?? VendorDefaultParametersKey.ConnectionUrl
- )
+ !this.getConfigurationKey(this.getSupervisionUrlOcppKey())
) {
this.addConfigurationKey(
- this.stationInfo.supervisionUrlOcppKey ?? VendorDefaultParametersKey.ConnectionUrl,
+ this.getSupervisionUrlOcppKey(),
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(
private getConfigurationFromFile(): ChargingStationConfiguration | null {
let configuration: ChargingStationConfiguration = null;
- if (this.configurationFile && fs.existsSync(this.configurationFile)) {
+ if (
+ this.getOcppPersistentConfiguration() &&
+ this.configurationFile &&
+ fs.existsSync(this.configurationFile)
+ ) {
try {
configuration = JSON.parse(
fs.readFileSync(this.configurationFile, 'utf8')
}
private saveConfiguration(): void {
- if (this.configurationFile) {
- try {
- if (!fs.existsSync(path.dirname(this.configurationFile))) {
- fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
+ if (this.getOcppPersistentConfiguration()) {
+ if (this.configurationFile) {
+ try {
+ if (!fs.existsSync(path.dirname(this.configurationFile))) {
+ fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
+ }
+ const fileDescriptor = fs.openSync(this.configurationFile, 'w');
+ fs.writeFileSync(fileDescriptor, JSON.stringify(this.configuration, null, 2));
+ fs.closeSync(fileDescriptor);
+ } catch (error) {
+ FileUtils.handleFileException(
+ this.logPrefix(),
+ FileType.ChargingStationConfiguration,
+ this.configurationFile,
+ error as NodeJS.ErrnoException
+ );
}
- const fileDescriptor = fs.openSync(this.configurationFile, 'w');
- fs.writeFileSync(fileDescriptor, JSON.stringify(this.configuration, null, 2));
- fs.closeSync(fileDescriptor);
- } catch (error) {
- FileUtils.handleFileException(
- this.logPrefix(),
- FileType.ChargingStationConfiguration,
- this.configurationFile,
- error as NodeJS.ErrnoException
+ } else {
+ logger.error(
+ `${this.logPrefix()} Trying to save charging station configuration to undefined file`
);
}
- } else {
- logger.error(
- `${this.logPrefix()} Trying to save charging station configuration to undefined file`
- );
}
}