From: Jérôme Benoit Date: Wed, 22 Nov 2023 20:59:35 +0000 (+0100) Subject: fix: ensure updated CS event is emitted on all possible changes X-Git-Tag: v1.2.26~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8baae8ee55048e93af74e94a2a806675d738e3bb;hp=f01a4e61a5ba423fbb9636747de36505cbf0e5bd;p=e-mobility-charging-stations-simulator.git fix: ensure updated CS event is emitted on all possible changes Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index e354b4b5..508567f3 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1853,6 +1853,7 @@ export class ChargingStation extends EventEmitter { commandName, commandPayload, ); + this.emit(ChargingStationEvents.updated); } private handleResponseMessage(response: Response): void { @@ -1929,7 +1930,6 @@ export class ChargingStation extends EventEmitter { logger.error(`${this.logPrefix()} ${errorMsg}`); throw new OCPPError(ErrorType.PROTOCOL_ERROR, errorMsg); } - this.emit(ChargingStationEvents.updated); } else { throw new OCPPError( ErrorType.PROTOCOL_ERROR, diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 64145bb3..14677814 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -14,7 +14,6 @@ import { import { OCPPError } from '../../../exception'; import { type ChangeConfigurationResponse, - ChargingStationEvents, type ClearChargingProfileResponse, ErrorType, type GenericResponse, @@ -693,7 +692,6 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16ChargePointStatus.Available, ); } - chargingStation.emit(ChargingStationEvents.updated); } private async handleResponseStopTransaction( @@ -750,7 +748,6 @@ export class OCPP16ResponseService extends OCPPResponseService { } resetConnectorStatus(chargingStation.getConnectorStatus(transactionConnectorId!)!); chargingStation.stopMeterValues(transactionConnectorId!); - chargingStation.emit(ChargingStationEvents.updated); const logMsg = `${chargingStation.logPrefix()} Transaction with id ${ requestPayload.transactionId } STOPPED on ${ diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index adbad777..2c90e1a3 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -8,6 +8,7 @@ import type { ChargingStation } from '../../charging-station'; import { OCPPError } from '../../exception'; import { PerformanceStatistics } from '../../performance'; import { + ChargingStationEvents, type ErrorCallback, type ErrorResponse, ErrorType, @@ -346,6 +347,7 @@ export abstract class OCPPRequestService { .catch(reject) .finally(() => { chargingStation.requests.delete(messageId); + chargingStation.emit(ChargingStationEvents.updated); }); }; @@ -370,6 +372,7 @@ export abstract class OCPPRequestService { ocppError, ); chargingStation.requests.delete(messageId); + chargingStation.emit(ChargingStationEvents.updated); reject(ocppError); };