/
hue.js
53 lines (46 loc) · 1.49 KB
/
hue.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
'use strict';
const tools = require('../tools.js');
function addHue(ip, device, options) {
let instance = tools.findInstance(options, 'hue', obj =>obj && obj.native && (obj.native.bridge === ip || obj.native.webServer === device._name));
if (!instance) {
instance = {
_id: tools.getNextInstanceID('hue', options),
common: {
name: 'hue'
},
native: {
bridge: ip
},
comment: {
add: [tools.translate(options.language, 'for %s', ip)],
inputs: [
{
name: 'native.user',
def: '',
type: 'text', // text, checkbox, number, select, password. Select requires
title: 'user' // see translation in words.js
}
]
}
};
options.newInstances.push(instance);
return true;
} else {
return false;
}
}
// just check if IP exists
function detect(ip, device, options, callback) {
let foundInstance = false;
device._upnp.forEach(upnp => {
if (!foundInstance && upnp['HUE-BRIDGEID'] || upnp['hue-bridgeid']) {
if (addHue(ip, device, options)) {
foundInstance = true;
}
}
});
callback(null, foundInstance, ip);
}
exports.detect = detect;
exports.type = ['upnp'];// make type=serial for USB sticks
exports.timeout = 500;