X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=cdf87cddc903cb173abd3492dfacf1bfdf8057db;hb=5b0e583fa396c09bd7bcfce6acf6d69c96ef0610;hp=ce036f7a1dc60b5841e08745548976ce31166098;hpb=b0c01ea0fbad0bc133bf2952be4af897b27bd128;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index ce036f7a..cdf87cdd 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -714,8 +714,8 @@ export default class ChargingStation { } async onMessage(messageEvent: MessageEvent): Promise { - let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, '', '']; - let responseCallback: (payload?, requestPayload?) => void; + let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, '', {}]; + let responseCallback: (payload?: Record | string, requestPayload?: Record) => void; let rejectCallback: (error: OCPPError) => void; let requestPayload: Record; let errMsg: string; @@ -746,7 +746,7 @@ export default class ChargingStation { throw new Error(`Response request for unknown message id ${messageId}`); } delete this._requests[messageId]; - responseCallback(commandName, requestPayload); + responseCallback(commandName.toString(), requestPayload); break; // Error Message case MessageType.CALL_ERROR_MESSAGE: @@ -760,7 +760,7 @@ export default class ChargingStation { throw new Error(`Error request for message id ${messageId} is not iterable`); } delete this._requests[messageId]; - rejectCallback(new OCPPError(commandName, commandPayload, errorDetails)); + rejectCallback(new OCPPError(commandName, commandPayload.toString(), errorDetails)); break; // Error default: @@ -837,14 +837,12 @@ export default class ChargingStation { } } - async sendError(messageId: string, err: Error | OCPPError, commandName: RequestCommand | IncomingRequestCommand): Promise { - // Check exception type: only OCPP error are accepted - const error = err instanceof OCPPError ? err : new OCPPError(ErrorType.INTERNAL_ERROR, err.message, err.stack && err.stack); + async sendError(messageId: string, error: OCPPError, commandName: RequestCommand | IncomingRequestCommand): Promise { // Send error return this.sendMessage(messageId, error, MessageType.CALL_ERROR_MESSAGE, commandName); } - async sendMessage(messageId: string, commandParams, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE, commandName: RequestCommand | IncomingRequestCommand): Promise { + async sendMessage(messageId: string, commandParams: any, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE, commandName: RequestCommand | IncomingRequestCommand): Promise { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; // Send a message through wsConnection @@ -927,7 +925,7 @@ export default class ChargingStation { }); } - async handleResponse(commandName: RequestCommand, payload, requestPayload): Promise { + async handleResponse(commandName: RequestCommand, payload: Record, requestPayload: Record): Promise { const responseCallbackFn = 'handleResponse' + commandName; if (typeof this[responseCallbackFn] === 'function') { await this[responseCallbackFn](payload, requestPayload); @@ -1038,7 +1036,7 @@ export default class ChargingStation { logger.debug(this._logPrefix() + ' Heartbeat response received: %j to Heartbeat request: %j', payload, requestPayload); } - async handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload): Promise { + async handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: Record | string): Promise { let response; // Call if (typeof this['handleRequest' + commandName] === 'function') {