From: Jérôme Benoit Date: Sun, 19 Apr 2020 20:20:27 +0000 (+0200) Subject: Use constants for common OCPP responses. X-Git-Tag: v1.0.1-0~350 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=dcab13bd38c8362aa507d29bc0eb5ce36b27a753;hp=fa098a85e622e86cf403edc783616ec990eaeb91;p=e-mobility-charging-stations-simulator.git Use constants for common OCPP responses. Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index f6ed3062..99532afa 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -499,36 +499,26 @@ class ChargingStation { const keyToChange = this._configuration.configurationKey.find((element) => element.key === commandPayload.key); if (keyToChange) { keyToChange.value = commandPayload.value; - return { - status: 'Accepted', - }; + return Constants.OCPP_RESPONSE_ACCEPTED; } - return { - status: 'Rejected', - }; + return Constants.OCPP_RESPONSE_REJECTED; } async handleRemoteStartTransaction(commandPayload) { const transactionConnectorID = (commandPayload.connectorId ? commandPayload.connectorId : '1'); if (this.isAuthorizationRequested() && this._authorizeRemoteTxRequests) { - // check if authorized + // Check if authorized if (this._authorizedKeys.find((value) => value === commandPayload.idTag)) { // Authorization successful start transaction setTimeout(() => this.sendStartTransaction(transactionConnectorID, commandPayload.idTag), 500); - return { - status: 'Accepted', - }; + return Constants.OCPP_RESPONSE_ACCEPTED; } // Start authorization checks - return { - status: 'Rejected', - }; + return Constants.OCPP_RESPONSE_REJECTED; } - // no local authorization check required => start transaction + // No local authorization check required => start transaction setTimeout(() => this.sendStartTransaction(transactionConnectorID, commandPayload.idTag), 500); - return { - status: 'Accepted', - }; + return Constants.OCPP_RESPONSE_ACCEPTED; } async sendStartTransaction(connectorID, idTag) { @@ -648,9 +638,7 @@ class ChargingStation { this.sendStopTransaction(commandPayload.transactionId, connector); } } - return { - status: 'Accepted', - }; + return Constants.OCPP_RESPONSE_ACCEPTED; } isAuthorizationRequested() { diff --git a/src/index.js b/src/index.js index 71edc5a9..3f47f1fe 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,7 @@ class Bootstrap { let numStationsTotal = 0; Configuration.getChargingStationTemplateURLs().forEach((stationURL) => { try { - // load file + // Load file const fileDescriptor = fs.openSync(stationURL.file, 'r'); const stationTemplate = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8')); fs.closeSync(fileDescriptor); diff --git a/src/utils/Constants.js b/src/utils/Constants.js index a7ffe4f4..d8a265c5 100644 --- a/src/utils/Constants.js +++ b/src/utils/Constants.js @@ -101,6 +101,8 @@ class Constants { static WS_UNSUPPORTED_DATA = 1007; + static OCPP_RESPONSE_ACCEPTED = {status: 'Accepted'}; + static OCPP_RESPONSE_REJECTED = {status: 'Rejected'}; static OCPP_SOCKET_TIMEOUT = 60000; // 60 sec static OCPP_JSON_CALL_MESSAGE = 2; // Client-to-Server static OCPP_JSON_CALL_RESULT_MESSAGE = 3; // Server-to-Client