[ProcedureName.LIST_CHARGING_STATIONS, this.handleListChargingStations.bind(this)],
[ProcedureName.ADD_CHARGING_STATIONS, this.handleAddChargingStations.bind(this)],
[ProcedureName.PERFORMANCE_STATISTICS, this.handlePerformanceStatistics.bind(this)],
+ [ProcedureName.SIMULATOR_STATE, this.handleSimulatorState.bind(this)],
[ProcedureName.START_SIMULATOR, this.handleStartSimulator.bind(this)],
[ProcedureName.STOP_SIMULATOR, this.handleStopSimulator.bind(this)]
])
if (!this.requestHandlers.has(command)) {
throw new BaseError(
- `${command} is not implemented to handle message payload ${JSON.stringify(
+ `'${command}' is not implemented to handle message payload ${JSON.stringify(
requestPayload,
undefined,
2
}
private async handleAddChargingStations (
- messageId?: string,
- procedureName?: ProcedureName,
+ _messageId?: string,
+ _procedureName?: ProcedureName,
requestPayload?: RequestPayload
): Promise<ResponsePayload> {
const { template, numberOfStations, options } = requestPayload as {
numberOfStations: number
options?: ChargingStationOptions
}
+ if (!Bootstrap.getInstance().getState().started) {
+ return {
+ status: ResponseStatus.FAILURE,
+ errorMessage:
+ 'Cannot add charging station(s) while the charging stations simulator is not started'
+ } satisfies ResponsePayload
+ }
+ if (typeof template !== 'string' || typeof numberOfStations !== 'number') {
+ return {
+ status: ResponseStatus.FAILURE,
+ errorMessage: 'Invalid request payload'
+ } satisfies ResponsePayload
+ }
if (!this.uiServer.chargingStationTemplates.has(template)) {
return {
status: ResponseStatus.FAILURE,
}
}
+ private handleSimulatorState (): ResponsePayload {
+ try {
+ return {
+ status: ResponseStatus.SUCCESS,
+ state: Bootstrap.getInstance().getState()
+ } satisfies ResponsePayload
+ } catch (error) {
+ return {
+ status: ResponseStatus.FAILURE,
+ errorMessage: (error as Error).message,
+ errorStack: (error as Error).stack
+ } satisfies ResponsePayload
+ }
+ }
+
private async handleStartSimulator (): Promise<ResponsePayload> {
try {
await Bootstrap.getInstance().start()