-
Notifications
You must be signed in to change notification settings - Fork 0
/
rstat.js
45 lines (32 loc) · 1.18 KB
/
rstat.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
39
40
41
42
43
44
45
module.exports = function(RED) {
'use strict';
var rtstat = require('rtstat');
function RadioThermIn(n) {
var node = this;
RED.nodes.createNode(node, n);
var ipaddr = n.ip;
// on input message
node.on('input', function(msg) {
var tstat = rtstat.tstat(ipaddr);
//obj.handleInputEvent(msg)
var outputPromise = tstat.ttemp();
outputPromise.then(function(value) {
node.send({ payload: value });
});
});
}
RED.nodes.registerType("rstat in", RadioThermIn);
RED.httpAdmin.get("/thermostats", RED.auth.needsPermission('rstat.read'), function(req, res) {
// which returns a promise that will resolve to an object with tstat uuids as keys and tstat objects as, um, objects
var tlist = rtstat.findThermostats();
var output = [];
tlist.then(function(thermostats) {
for (var key in thermostats) {
// 'key' is this thermostat's uuid
var thisTstat = thermostats[key];
output.push(thisTstat.ipAddress);
}
res.json(output);
});
});
}