-
Notifications
You must be signed in to change notification settings - Fork 0
/
nr-balanceclearing.js
38 lines (36 loc) · 1.37 KB
/
nr-balanceclearing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module.exports = function(RED) {
function EBNode(config) {
RED.nodes.createNode(this,config);
const node = this;
const storage = node.context();
const balance = RED.nodes.getNode(config.balance);
node.on('input', async function(msg) {
const clearing = balance.clearing();
let payload = {
upstream:{},
downstream:{},
meta:{}
}
const labelDirection = function(dir) {
for (let [key, value] of Object.entries(clearing[dir])) {
if(key.indexOf('_') > 0 ){
key = key.substr(0,key.indexOf('_'));
}
const _labelNode = RED.nodes.getNode(key);
if((typeof _labelNode !== 'undefined')&&(_labelNode !== null)) {
_labelNode.cleared();
if(typeof _labelNode.name == 'undefined') { _labelNode.name = key; }
payload[dir][_labelNode.name] = value;
}
}
}
labelDirection('upstream');
labelDirection('downstream');
payload.meta = clearing.meta;
payload.timeframe = clearing.timeframe;
payload.reading = clearing.reading;
node.send({payload:payload});
});
}
RED.nodes.registerType("Clearing",EBNode);
}