Skip to content

Commit

Permalink
For installations that return total put that in the status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dirkjanfaber committed Jul 9, 2024
1 parent c07e741 commit 79e9a34
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/nodes/vrm-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down

0 comments on commit 79e9a34

Please sign in to comment.