-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from klein0r/master
Added LaMetric and WLED
- Loading branch information
Showing
6 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Older changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const tools = require('../tools.js'); | ||
|
||
function addInstance(ip, device, options) { | ||
let instance = tools.findInstance(options, 'lametric', obj => obj.native.lametricIp === ip); | ||
|
||
if (!instance) { | ||
instance = { | ||
_id: tools.getNextInstanceID('lametric', options), | ||
common: { | ||
name: 'lametric' | ||
}, | ||
native: { | ||
lametricIp: ip, | ||
}, | ||
comment: { | ||
add: 'LaMetric device' | ||
} | ||
}; | ||
options.newInstances.push(instance); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
function detect(ip, device, options, callback) { | ||
let foundInstance = false; | ||
|
||
device._upnp.forEach(upnp => { | ||
if (!foundInstance && upnp._location && upnp._location.includes('LaMetric Time')) { | ||
options.log.debug('LaMetric device detected at: ' + ip); | ||
if (addInstance(ip, device, options)) { | ||
foundInstance = true; | ||
} | ||
} | ||
}); | ||
|
||
callback(null, foundInstance, ip); | ||
} | ||
|
||
exports.detect = detect; | ||
exports.type = ['upnp']; | ||
exports.timeout = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const tools = require('../tools.js'); | ||
|
||
function addInstance(ip, options) { | ||
let instance = tools.findInstance(options, 'wled', obj => obj.native.devices.filter(device => device.ip === ip)); | ||
|
||
if (!instance) { | ||
instance = { | ||
_id: tools.getNextInstanceID('wled', options), | ||
common: { | ||
name: 'wled', | ||
}, | ||
native: { | ||
devices: { | ||
wled: { | ||
ip | ||
} | ||
} | ||
}, | ||
comment: { | ||
add: ['WLED', ip] | ||
} | ||
}; | ||
options.newInstances.push(instance); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
function detect(ip, device, options, callback) { | ||
if (device?._mdns?.PTR && device._mdns.PTR.datax.includes('_wled._tcp.local')) { | ||
callback(null, addInstance(ip, options), ip); | ||
} else { | ||
callback(null, false, ip); | ||
} | ||
} | ||
|
||
exports.detect = detect; | ||
exports.type = ['mdns']; | ||
exports.timeout = 1500; |