From 193d2c0a14e09db6af0a618525f8e0c8aef58cfe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 2 May 2021 20:34:45 +0200 Subject: [PATCH] Fix SRPC call type counting in statistics. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 2 +- src/charging-station/ocpp/OCPPRequestService.ts | 7 +++---- src/types/ocpp/Requests.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b5ec5209..44327562 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -517,7 +517,7 @@ export default class ChargingStation { private async onMessage(messageEvent: MessageEvent): Promise { let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, {}, {}]; - let responseCallback: (payload?: Record | string, requestPayload?: Record) => void; + let responseCallback: (payload: Record | string, requestPayload: Record) => void; let rejectCallback: (error: OCPPError) => void; let requestPayload: Record; let errMsg: string; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 5615eb77..20163f7d 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -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 { + public async sendMessage(messageId: string, commandParams: any, messageType: MessageType, commandName: RequestCommand | IncomingRequestCommand): Promise { // 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, requestPayload: Record): Promise { 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 diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index d4388efe..26283cc9 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -27,6 +27,6 @@ export const IncomingRequestCommand = { ...OCPP16IncomingRequestCommand }; -export type Request = [(payload?: Record, requestPayload?: Record) => void, (error?: OCPPError) => void, Record]; +export type Request = [(payload: Record, requestPayload: Record) => void, (error: OCPPError) => void, Record]; export type IncomingRequest = [MessageType, string, IncomingRequestCommand, Record, Record]; -- 2.34.1