From: Jérôme Benoit Date: Sat, 26 Nov 2022 21:19:21 +0000 (+0100) Subject: Type alias for OCPP stack response and error handling X-Git-Tag: v1.1.88~14 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d900c8d7647a6119a2c8f9f1c283422a8398ef75;p=e-mobility-charging-stations-simulator.git Type alias for OCPP stack response and error handling Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 1699f046..04c33a10 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -42,11 +42,13 @@ import { AvailabilityType, BootNotificationRequest, CachedRequest, + ErrorCallback, HeartbeatRequest, IncomingRequest, IncomingRequestCommand, MeterValuesRequest, RequestCommand, + ResponseCallback, StatusNotificationRequest, } from '../types/ocpp/Requests'; import { @@ -1412,8 +1414,8 @@ export default class ChargingStation { let errorType: ErrorType; let errorMessage: string; let errorDetails: JsonType; - let responseCallback: (payload: JsonType, requestPayload: JsonType) => void; - let errorCallback: (error: OCPPError, requestStatistic?: boolean) => void; + let responseCallback: ResponseCallback; + let errorCallback: ErrorCallback; let requestCommandName: RequestCommand | IncomingRequestCommand; let requestPayload: JsonType; let cachedRequest: CachedRequest; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index bdfffc37..6c241042 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -10,10 +10,12 @@ import type { JsonObject, JsonType } from '../../types/JsonType'; import { ErrorType } from '../../types/ocpp/ErrorType'; import { MessageType } from '../../types/ocpp/MessageType'; import { + ErrorCallback, IncomingRequestCommand, OutgoingRequest, RequestCommand, RequestParams, + ResponseCallback, ResponseType, } from '../../types/ocpp/Requests'; import type { ErrorResponse, Response } from '../../types/ocpp/Responses'; @@ -308,8 +310,8 @@ export default abstract class OCPPRequestService { messagePayload: JsonType | OCPPError, messageType: MessageType, commandName?: RequestCommand | IncomingRequestCommand, - responseCallback?: (payload: JsonType, requestPayload: JsonType) => void, - errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void + responseCallback?: ResponseCallback, + errorCallback?: ErrorCallback ): string { let messageToSend: string; // Type of message diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index aeedae02..1aa015b6 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -36,9 +36,13 @@ export const IncomingRequestCommand = { export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType]; +export type ResponseCallback = (payload: JsonType, requestPayload: JsonType) => void; + +export type ErrorCallback = (error: OCPPError, requestStatistic?: boolean) => void; + export type CachedRequest = [ - (payload: JsonType, requestPayload: JsonType) => void, - (error: OCPPError, requestStatistic?: boolean) => void, + ResponseCallback, + ErrorCallback, RequestCommand | IncomingRequestCommand, JsonType ];