From 79e9a340829315d229eea01c7a26c4c73c13c4e0 Mon Sep 17 00:00:00 2001 From: Dirk-Jan Faber Date: Tue, 9 Jul 2024 20:44:55 +0200 Subject: [PATCH] For installations that return total put that in the status When the API query returns a field that within totals, put the key, with the underscores replaced by spaces, plus the (one digit rounded) value in the status field of the node. --- src/nodes/vrm-api.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nodes/vrm-api.js b/src/nodes/vrm-api.js index bbed928..b03c0be 100644 --- a/src/nodes/vrm-api.js +++ b/src/nodes/vrm-api.js @@ -267,11 +267,17 @@ module.exports = function (RED) { default: // get axios.get(url, { params: options, headers }).then(function (response) { if (response.status === 200) { + let text = 'Ok' msg.payload = response.data if (installations !== 'gps-download') { msg.payload.options = options } - node.status({ fill: 'green', shape: 'dot', text: 'Ok' }) + if (response.data.totals) { + const key = Object.keys(response.data.totals)[0] + const value = response.data.totals[key] + text = `${key.replace(/_/g, ' ')}: ${value.toFixed(1)}` + } + node.status({ fill: 'green', shape: 'dot', text }) } else { node.status({ fill: 'yellow', shape: 'dot', text: response.status }) }