diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-11-18 13:02:20 +0000 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-11-18 13:02:20 +0000 |
| commit | c47447f9fca976b9272197085ef35d10e281de6e (patch) | |
| tree | 919ed8935013d2a73125f6e6f1ae062ab170ac25 | |
| parent | e561e88b86dc1e52e1d11881e765a2dc270c673f (diff) | |
| download | tplink-energy-monitor-c47447f9fca976b9272197085ef35d10e281de6e.tar.xz tplink-energy-monitor-c47447f9fca976b9272197085ef35d10e281de6e.zip | |
Exclude devices without monitoring API e.g hs100bugfixes
Fixes #7
| -rw-r--r-- | services/device-manager.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/services/device-manager.js b/services/device-manager.js index 1e17f75..451734e 100644 --- a/services/device-manager.js +++ b/services/device-manager.js @@ -7,12 +7,19 @@ var devices = []; client.startDiscovery({ deviceTypes: ['plug'], discoveryTimeout: 20000 - }).on('plug-new', plug => { - console.log('Found device: ' + plug.alias + ' [' + plug.deviceId + ']'); - devices.push(plug); + }).on('plug-new', registerPlug); - dataLogger.startLogging(plug); -}); +function registerPlug(plug) { + + if (plug.supportsEmeter) { + console.log('Found device with energy monitor support: ' + plug.alias + ' [' + plug.deviceId + ']'); + devices.push(plug); + dataLogger.startLogging(plug); + } else { + console.log('Skipping device: ' + plug.alias + ' [' + plug.deviceId + ']. Energy monitoring not supported.'); + } + +} module.exports.getDevice = function(deviceId) { |