From 690e5af73261da3434b37ef02c67c22ff19b8e5e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 14 Jan 2021 22:15:17 +0100 Subject: [PATCH] Fix type conversion to string. 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 | 12 ++++++------ src/types/ocpp/Requests.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index cdf87cdd..dce900c7 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -714,7 +714,7 @@ export default class ChargingStation { } async onMessage(messageEvent: MessageEvent): Promise { - let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, '', {}]; + 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; @@ -746,7 +746,7 @@ export default class ChargingStation { throw new Error(`Response request for unknown message id ${messageId}`); } delete this._requests[messageId]; - responseCallback(commandName.toString(), requestPayload); + responseCallback(commandName, requestPayload); break; // Error Message case MessageType.CALL_ERROR_MESSAGE: @@ -874,7 +874,7 @@ export default class ChargingStation { } // Yes: Send Message this._wsConnection.send(messageToSend); - } else { + } else if (commandName !== RequestCommand.BOOT_NOTIFICATION) { let dups = false; // Handle dups in buffer for (const message of this._messageQueue) { @@ -901,7 +901,7 @@ export default class ChargingStation { } // Function that will receive the request's response - async function responseCallback(payload, requestPayload): Promise { + async function responseCallback(payload: Record | string, requestPayload: Record): Promise { if (self.getEnableStatistics()) { self._statistics.addMessage(commandName, messageType); } @@ -925,7 +925,7 @@ export default class ChargingStation { }); } - async handleResponse(commandName: RequestCommand, payload: Record, requestPayload: Record): Promise { + async handleResponse(commandName: RequestCommand, payload: Record | string, requestPayload: Record): Promise { const responseCallbackFn = 'handleResponse' + commandName; if (typeof this[responseCallbackFn] === 'function') { await this[responseCallbackFn](payload, requestPayload); @@ -1036,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: Record | string): Promise { + async handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: Record): Promise { let response; // Call if (typeof this['handleRequest' + commandName] === 'function') { diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index 7ce4979e..ea2da243 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -8,4 +8,4 @@ export default interface Requests { export type Request = [(payload?: Record, requestPayload?: Record) => void, (error?: OCPPError) => void, Record]; -export type IncomingRequest = [MessageType, string, IncomingRequestCommand, Record | string, Record]; +export type IncomingRequest = [MessageType, string, IncomingRequestCommand, Record, Record]; -- 2.34.1