-
Notifications
You must be signed in to change notification settings - Fork 0
/
netgear.js
60 lines (45 loc) · 1.57 KB
/
netgear.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var Netgear = require('netgear');
var _ = require('underscore');
module.exports = function (RED) {
function NetgearAllDevices(config) {
RED.nodes.createNode(this, config);
this.creds = RED.nodes.getNode(config.creds);
var node = this;
this.on('input', function (msg) {
//const Netgear = require('netgear');
const options = { password: this.creds.password, host: this.creds.host };
//console.log("options: " , options);
if(this.password === "" || this.host === "") {
msg.payload = "ERROR: password or host emtpy.";
node.send(msg);
}
else {
(async () => {
//console.log("Status: " + await getDevices())
let devArr = await getDevices(options);
msg.payload = devArr;
node.send(msg);
})()
}
});
}
RED.nodes.registerType('netgear-all-devices', NetgearAllDevices);
function NetgearConfigNode(n) {
RED.nodes.createNode(this, n);
this.password = n.password;
this.host = n.host;
}
RED.nodes.registerType('netgear-config-node', NetgearConfigNode);
};
async function getDevices(options) {
try {
const router = new Netgear();
await router.login(options);
const deviceArray = await router.getAttachedDevices();
//console.log(deviceArray);
return (deviceArray);
} catch (error) {
//console.log(error);
return (error);
}
}