diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-11-18 13:12:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-18 13:12:38 +0000 |
| commit | 5877729bdda9ca20f164d9dff634f6bf3aa54204 (patch) | |
| tree | 6401b44495f96411cb14b3b33e5c7ae269929159 /services/device-manager.js | |
| parent | fa6a6669d8add3b76ea17dec49bd1d0ae1a7c341 (diff) | |
| parent | c47447f9fca976b9272197085ef35d10e281de6e (diff) | |
| download | tplink-energy-monitor-5877729bdda9ca20f164d9dff634f6bf3aa54204.tar.xz tplink-energy-monitor-5877729bdda9ca20f164d9dff634f6bf3aa54204.zip | |
Merge pull request #12 from jamesbarnett91/bugfixesv0.7
Fix voltage reading and exclude unsupported devices from search
Diffstat (limited to 'services/device-manager.js')
| -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) { |