X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=125baf4073366623f05c67797d6e375ef532f148;hb=edd134392e237a3242dc2093341df70244c51472;hp=29c740a187310d11fe5a0dedf4ea3e05de8d016c;hpb=3a13fc92f2bc5236dcde66fe5e79e0cea89f1c3d;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 29c740a1..125baf40 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -10,11 +10,13 @@ import type { JsonObject, JsonType } from '../../types/JsonType'; import { ErrorType } from '../../types/ocpp/ErrorType'; import { MessageType } from '../../types/ocpp/MessageType'; import { - IncomingRequestCommand, - OutgoingRequest, + type ErrorCallback, + type IncomingRequestCommand, + type OutgoingRequest, RequestCommand, - RequestParams, - ResponseType, + type RequestParams, + type ResponseCallback, + type ResponseType, } from '../../types/ocpp/Requests'; import type { ErrorResponse, Response } from '../../types/ocpp/Responses'; import Constants from '../../utils/Constants'; @@ -187,10 +189,10 @@ export default abstract class OCPPRequestService { // Check if wsConnection opened if (chargingStation.isWebSocketConnectionOpened() === true) { // Yes: Send Message - const beginId = PerformanceStatistics.beginMeasure(commandName); + const beginId = PerformanceStatistics.beginMeasure(commandName as string); // FIXME: Handle sending error chargingStation.wsConnection.send(messageToSend); - PerformanceStatistics.endMeasure(commandName, beginId); + PerformanceStatistics.endMeasure(commandName as string, beginId); logger.debug( `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString( messageType @@ -231,13 +233,10 @@ export default abstract class OCPPRequestService { /** * Function that will receive the request's response * - * @param payload - * @param requestPayload + * @param payload - + * @param requestPayload - */ - async function responseCallback( - payload: JsonType, - requestPayload: JsonType - ): Promise { + function responseCallback(payload: JsonType, requestPayload: JsonType): void { if (chargingStation.getEnableStatistics() === true) { chargingStation.performanceStatistics.addRequestStatistic( commandName, @@ -245,26 +244,29 @@ export default abstract class OCPPRequestService { ); } // Handle the request's response - try { - await self.ocppResponseService.responseHandler( + self.ocppResponseService + .responseHandler( chargingStation, commandName as RequestCommand, payload, requestPayload - ); - resolve(payload); - } catch (error) { - reject(error); - } finally { - chargingStation.requests.delete(messageId); - } + ) + .then(() => { + resolve(payload); + }) + .catch((error) => { + reject(error); + }) + .finally(() => { + chargingStation.requests.delete(messageId); + }); } /** * Function that will receive the request's error response * - * @param error - * @param requestStatistic + * @param error - + * @param requestStatistic - */ function errorCallback(error: OCPPError, requestStatistic = true): void { if (requestStatistic === true && chargingStation.getEnableStatistics() === true) { @@ -308,8 +310,8 @@ export default abstract class OCPPRequestService { messagePayload: JsonType | OCPPError, messageType: MessageType, commandName?: RequestCommand | IncomingRequestCommand, - responseCallback?: (payload: JsonType, requestPayload: JsonType) => Promise, - errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void + responseCallback?: ResponseCallback, + errorCallback?: ErrorCallback ): string { let messageToSend: string; // Type of message @@ -374,10 +376,10 @@ export default abstract class OCPPRequestService { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - public abstract requestHandler( + public abstract requestHandler( chargingStation: ChargingStation, commandName: RequestCommand, commandParams?: JsonType, params?: RequestParams - ): Promise; + ): Promise; }