fix: ensure updated CS event is emitted on all possible changes
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 22 Nov 2023 20:59:35 +0000 (21:59 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 22 Nov 2023 20:59:35 +0000 (21:59 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/OCPPRequestService.ts

index e354b4b5164979c794e43a26b740ed9e2295db9b..508567f37e7999a97fc3ad20564b2c37b1e6ae77 100644 (file)
@@ -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,
index 64145bb3db2fe05a7bf840462092a85ff22f7756..146778141abdbcc3c72b7860d2fde9b5d8792c8e 100644 (file)
@@ -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 ${
index adbad7774feedbf21baea86e6865878869146795..2c90e1a374df1bcc6ee5bf88a2f3f53a4ffa4bec 100644 (file)
@@ -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);
         };