From 73edcc9405a412de91008d2926112c4b8ada3607 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 30 Nov 2023 16:38:10 +0100 Subject: [PATCH] fix: ensure UI server remains active at simulator stop MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 4 +++- src/charging-station/ChargingStation.ts | 2 ++ src/charging-station/Helpers.ts | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 66207645..503dfb0b 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -195,7 +195,6 @@ export class Bootstrap extends EventEmitter { await this.workerImplementation?.stop(); delete this.workerImplementation; this.removeAllListeners(); - this.uiServer?.stop(); await this.storage?.close(); delete this.storage; this.resetCounters(); @@ -212,6 +211,8 @@ export class Bootstrap extends EventEmitter { public async restart(stopChargingStations?: boolean): Promise { await this.stop(stopChargingStations); + Configuration.getConfigurationSection(ConfigurationSection.uiServer) + .enabled === false && this.uiServer?.stop(); await this.start(); } @@ -407,6 +408,7 @@ export class Bootstrap extends EventEmitter { this.stop() .then(() => { console.info(`${chalk.green('Graceful shutdown')}`); + this.uiServer?.stop(); // stop() asks for charging stations to stop by default this.waitChargingStationsStopped() .then(() => { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6acd4018..aa251e39 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -22,6 +22,7 @@ import { import { buildConnectorsMap, checkChargingStation, + checkConfiguration, checkConnectorsConfiguration, checkStationInfoConnectorStatus, checkTemplate, @@ -1201,6 +1202,7 @@ export class ChargingStation extends EventEmitter { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (stationConfiguration?.connectorsStatus || stationConfiguration?.evsesStatus) ) { + checkConfiguration(stationConfiguration, this.logPrefix(), this.configurationFile); this.initializeConnectorsOrEvsesFromFile(stationConfiguration); } else { this.initializeConnectorsOrEvsesFromTemplate(stationTemplate); diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 13721bd6..f31ee7f0 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -33,6 +33,7 @@ import { ChargingProfileKindType, ChargingRateUnitType, type ChargingSchedulePeriod, + type ChargingStationConfiguration, type ChargingStationInfo, type ChargingStationTemplate, ChargingStationWorkerMessageEvents, @@ -253,6 +254,23 @@ export const checkTemplate = ( } }; +export const checkConfiguration = ( + stationConfiguration: ChargingStationConfiguration | undefined, + logPrefix: string, + configurationFile: string, +): void => { + if (isNullOrUndefined(stationConfiguration)) { + const errorMsg = `Failed to read charging station configuration file ${configurationFile}`; + logger.error(`${logPrefix} ${errorMsg}`); + throw new BaseError(errorMsg); + } + if (isEmptyObject(stationConfiguration!)) { + const errorMsg = `Empty charging station configuration from file ${configurationFile}`; + logger.error(`${logPrefix} ${errorMsg}`); + throw new BaseError(errorMsg); + } +}; + export const checkConnectorsConfiguration = ( stationTemplate: ChargingStationTemplate, logPrefix: string, -- 2.34.1