-
Notifications
You must be signed in to change notification settings - Fork 48
/
homepilot.js
39 lines (35 loc) · 1.3 KB
/
homepilot.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
'use strict';
const tools = require('../tools.js');
// based on miele
const adapterName = 'homepilot';
const reIsHomepilot = /<h1 id="form-container-automation-conflict-detection-title-resolve">/;
function detect(ip, device, options, callback) {
if (device._source !== 'ip') return callback(null, false, ip);
tools.httpGet('http://' + ip + '/actor.do', (err, data) => {
let ar;
if (!err && data && reIsHomepilot.test(data)) {
let instance = tools.findInstance (options, adapterName, obj => true);
if (!instance) {
const name = device._name ? device._name : '';
instance = {
_id: tools.getNextInstanceID (adapterName, options),
common: {
name: adapterName,
title: 'Homepilot (' + ip + (name ? (' - ' + name) : '') + ')'
},
native: {
ip: ip
},
comment: {
add: [name, ip]
}
};
options.newInstances.push(instance);
return callback (null, true, ip);
}
}
callback(null, false, ip);
});
}
exports.detect = detect;
exports.type = ['ip'];