From: Jérôme Benoit Date: Thu, 14 Jan 2021 21:15:17 +0000 (+0100) Subject: Fix type conversion to string. X-Git-Tag: v1.0.1-0~146 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=690e5af73261da3434b37ef02c67c22ff19b8e5e;p=e-mobility-charging-stations-simulator.git Fix type conversion to string. Signed-off-by: Jérôme Benoit --- 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];