-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmelview-unitquery.js
More file actions
26 lines (22 loc) · 871 Bytes
/
melview-unitquery.js
File metadata and controls
26 lines (22 loc) · 871 Bytes
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
module.exports = function (RED) {
function UnitQueryNode(config) {
RED.nodes.createNode(this, config);
this.melviewConnection = RED.nodes.getNode(config.melviewConnection);
this.building = config.building;
this.unit = config.unit;
const node = this;
const melviewConnection = this.melviewConnection;
node.on('input', function (msg) {
let query = {
'building': config.building,
'unit': config.unit
};
melviewConnection.GetUnits(function (response) {
let building = response.find(b => b.buildingid === query.building);
msg.payload = building.units.find(u => u.unitid === query.unit);
node.send(msg);
});
});
}
RED.nodes.registerType("unit-query", UnitQueryNode);
};