From d900c8d7647a6119a2c8f9f1c283422a8398ef75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 26 Nov 2022 22:19:21 +0100 Subject: [PATCH] Type alias for OCPP stack response and error handling 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 | 6 ++++-- src/charging-station/ocpp/OCPPRequestService.ts | 6 ++++-- src/types/ocpp/Requests.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) 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 ]; -- 2.34.1