Fix SRPC call type counting in statistics.
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 May 2021 18:34:45 +0000 (20:34 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 May 2021 18:34:45 +0000 (20:34 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/types/ocpp/Requests.ts

index b5ec5209ad8a56a2aa713a08de0a50da529b881e..44327562d69274da428066f7a58f0106a668ec2b 100644 (file)
@@ -517,7 +517,7 @@ export default class ChargingStation {
 
   private async onMessage(messageEvent: MessageEvent): Promise<void> {
     let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, {}, {}];
-    let responseCallback: (payload?: Record<string, unknown> | string, requestPayload?: Record<string, unknown>) => void;
+    let responseCallback: (payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>) => void;
     let rejectCallback: (error: OCPPError) => void;
     let requestPayload: Record<string, unknown>;
     let errMsg: string;
index 5615eb7705411c04f3054e07b2e1ed4daa0628e8..20163f7d7d157186c56556c553963816f32b47cc 100644 (file)
@@ -21,8 +21,7 @@ export default abstract class OCPPRequestService {
     this.ocppResponseService = ocppResponseService;
   }
 
-  public async sendMessage(messageId: string, commandParams: any, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE,
-      commandName: RequestCommand | IncomingRequestCommand): Promise<any> {
+  public async sendMessage(messageId: string, commandParams: any, messageType: MessageType, commandName: RequestCommand | IncomingRequestCommand): Promise<any> {
     // eslint-disable-next-line @typescript-eslint/no-this-alias
     const self = this;
     // Send a message through wsConnection
@@ -77,7 +76,7 @@ export default abstract class OCPPRequestService {
        */
       async function responseCallback(payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
         if (self.chargingStation.getEnableStatistics()) {
-          self.chargingStation.statistics.addMessage(commandName, messageType);
+          self.chargingStation.statistics.addMessage(commandName, MessageType.CALL_RESULT_MESSAGE);
         }
         // Send the response
         await self.ocppResponseService.handleResponse(commandName as RequestCommand, payload, requestPayload);
@@ -91,7 +90,7 @@ export default abstract class OCPPRequestService {
        */
       function rejectCallback(error: OCPPError): void {
         if (self.chargingStation.getEnableStatistics()) {
-          self.chargingStation.statistics.addMessage(commandName, messageType);
+          self.chargingStation.statistics.addMessage(commandName, MessageType.CALL_ERROR_MESSAGE);
         }
         logger.debug(`${self.chargingStation.logPrefix()} Error: %j occurred when calling command %s with parameters: %j`, error, commandName, commandParams);
         // Build Exception
index d4388efe7c9c957aa3a1a4fe82374e608cea6881..26283cc91ea8e0391e5e5a3034d85728ebeb499c 100644 (file)
@@ -27,6 +27,6 @@ export const IncomingRequestCommand = {
   ...OCPP16IncomingRequestCommand
 };
 
-export type Request = [(payload?: Record<string, unknown>, requestPayload?: Record<string, unknown>) => void, (error?: OCPPError) => void, Record<string, unknown>];
+export type Request = [(payload: Record<string, unknown>, requestPayload: Record<string, unknown>) => void, (error: OCPPError) => void, Record<string, unknown>];
 
 export type IncomingRequest = [MessageType, string, IncomingRequestCommand, Record<string, unknown>, Record<string, unknown>];