1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 11:36:58 +00:00

add device filter (#545)

* add device filter

* fix jslint error of pushbullet

* fix pushbullet.js
This commit is contained in:
Hiroyuki Okada 2019-05-26 22:23:25 +09:00 committed by Dave Conway-Jones
parent f20d00a972
commit a226e6a308

View File

@ -491,7 +491,7 @@ module.exports = function(RED) {
res.send("[]"); res.send("[]");
return onError(err, config); return onError(err, config);
} }
res.send(JSON.stringify(chans.devices)); res.send(JSON.stringify(filterdActiveDevices(chans.devices)));
}); });
} }
else if (cred && cred.apikey) { else if (cred && cred.apikey) {
@ -501,7 +501,7 @@ module.exports = function(RED) {
res.send("[]"); res.send("[]");
return onError(err, config); return onError(err, config);
} }
res.send(JSON.stringify(chans.devices)); res.send(JSON.stringify(filterdActiveDevices(chans.devices)));
}); });
} }
else if (req.query.apikey) { else if (req.query.apikey) {
@ -511,7 +511,7 @@ module.exports = function(RED) {
res.send("[]"); res.send("[]");
return onError(err, config); return onError(err, config);
} }
res.send(JSON.stringify(chans.devices)); res.send(JSON.stringify(filterdActiveDevices(chans.devices)));
}); });
} }
else { else {
@ -519,6 +519,16 @@ module.exports = function(RED) {
} }
}); });
function filterdActiveDevices(devices){
var activeDevices = [];
for(var i=0;i<devices.length;i++){
if(devices[i].active){
activeDevices.push(devices[i]);
}
}
return activeDevices;
}
function PushbulletIn(n) { function PushbulletIn(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
var self = this; var self = this;