aboutsummaryrefslogtreecommitdiff
path: root/services/device-manager.js
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2018-11-18 13:12:38 +0000
committerGitHub <noreply@github.com>2018-11-18 13:12:38 +0000
commit5877729bdda9ca20f164d9dff634f6bf3aa54204 (patch)
tree6401b44495f96411cb14b3b33e5c7ae269929159 /services/device-manager.js
parentfa6a6669d8add3b76ea17dec49bd1d0ae1a7c341 (diff)
parentc47447f9fca976b9272197085ef35d10e281de6e (diff)
downloadtplink-energy-monitor-0.7.tar.xz
tplink-energy-monitor-0.7.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.js17
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) {