aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/data-fetcher.js22
-rw-r--r--services/device-manager.js17
2 files changed, 29 insertions, 10 deletions
diff --git a/services/data-fetcher.js b/services/data-fetcher.js
index 7ef3594..b552952 100644
--- a/services/data-fetcher.js
+++ b/services/data-fetcher.js
@@ -26,11 +26,7 @@ function fetchRealtimeUsage() {
let deviceId = device.deviceId;
device.emeter.getRealtime().then(response => {
- // Voltage seems to be reported as its peak to peak value, not RMS.
- // Show the RMS value since thats what would you expect to see.
- // i.e. 220v not 310v (in the U.K)
- response.voltage = response.voltage / Math.sqrt(2);
-
+ response.voltage = normaliseVoltage(response, device);
updateCache(cachedRealtimeUsageData, deviceId, response);
dataBroadcaster.broadcastRealtimeUsageUpdate(deviceId, response);
@@ -266,6 +262,22 @@ function updateCache(cache, deviceId, data) {
}
}
+/*
+* On older firmware versions (not sure exactly which since its not documented anywhere)
+* voltage seems to be reported as its peak to peak value, not RMS.
+* So we show the RMS value since thats what would you expect to see.
+* i.e. 220v not 310v (in the U.K).
+* This is applied for all 1.0.x firmware versions.
+*/
+function normaliseVoltage(response, device) {
+ if (device.softwareVersion.startsWith("1.0")) {
+ return response.voltage / Math.sqrt(2);
+ }
+ else {
+ return response.voltage;
+ }
+}
+
module.exports.getCachedData = function(deviceId) {
return {
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) {