From facd8ebde74a5d3d16ed65f88d942abcbe79a1e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 18 Oct 2020 00:46:53 +0200 Subject: [PATCH] Make getConfiguration response smarter. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../abb.station-template.json | 6 +++ src/charging-station/ChargingStation.js | 38 ++++++++++++++----- src/utils/Utils.js | 7 ++++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/assets/station-templates/abb.station-template.json b/src/assets/station-templates/abb.station-template.json index f256c37e..1fef0e8a 100644 --- a/src/assets/station-templates/abb.station-template.json +++ b/src/assets/station-templates/abb.station-template.json @@ -35,6 +35,12 @@ "key": "AuthorizeRemoteTxRequests", "readonly": false, "value": false + }, + { + "key": "VendorKey", + "readonly": false, + "value": "VendorValue", + "visible": false } ] }, diff --git a/src/charging-station/ChargingStation.js b/src/charging-station/ChargingStation.js index 38e9f582..91232e5f 100644 --- a/src/charging-station/ChargingStation.js +++ b/src/charging-station/ChargingStation.js @@ -531,22 +531,22 @@ class ChargingStation { handleResponseStopTransaction(payload, requestPayload) { if (payload.idTagInfo && payload.idTagInfo.status) { - logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: ' + payload.idTagInfo.status ); + logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: ' + payload.idTagInfo.status); } else { logger.debug(this._basicFormatLog() + ' Stop transaction ' + requestPayload.transactionId + ' response status: Unknown'); } } - handleResponseStatusNotification(payload) { - logger.debug(this._basicFormatLog() + ' Status notification response received: %j', payload); + handleResponseStatusNotification(payload, requestPayload) { + logger.debug(this._basicFormatLog() + ' Status notification response received: %j to status notification request: %j', payload, requestPayload); } - handleResponseMeterValues(payload) { - logger.debug(this._basicFormatLog() + ' MeterValues response received: %j', payload); + handleResponseMeterValues(payload, requestPayload) { + logger.debug(this._basicFormatLog() + ' MeterValues response received: %j to MeterValues request: %j', payload, requestPayload); } - handleResponseHeartbeat(payload) { - logger.debug(this._basicFormatLog() + ' Heartbeat response received: %j', payload); + handleResponseHeartbeat(payload, requestPayload) { + logger.debug(this._basicFormatLog() + ' Heartbeat response received: %j to Heartbeat request: %j', payload, requestPayload); } async handleRequest(messageId, commandName, commandPayload) { @@ -560,7 +560,7 @@ class ChargingStation { } catch (error) { // Log logger.error(this._basicFormatLog() + ' Handle request error: ' + error); - // Send back response to inform back end + // Send back response to inform backend await this.sendError(messageId, error); } } else { @@ -573,7 +573,27 @@ class ChargingStation { } async handleGetConfiguration(commandPayload) { - return this._configuration; + const configurationKey = []; + const unknownKey = []; + for (const configuration of this._configuration.configurationKey) { + if (Utils.isUndefined(configuration.visible)) { + configuration.visible = true; + } else { + configuration.visible = Utils.convertToBoolean(configuration.visible); + } + if (!configuration.visible) { + continue; + } + configurationKey.push({ + key: configuration.key, + readonly: configuration.readonly, + value: configuration.value, + }); + } + return { + configurationKey, + unknownKey, + }; } async handleChangeConfiguration(commandPayload) { diff --git a/src/utils/Utils.js b/src/utils/Utils.js index 5f467fea..446f5241 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -135,6 +135,13 @@ class Utils { static cloneJSonDocument(jsonDocument) { return JSON.parse(JSON.stringify(jsonDocument)); } + + static isUndefined(value) { + if (typeof value === 'undefined') { + return true; + } + return false; + } } module.exports = Utils; -- 2.34.1