aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2018-11-18 12:51:00 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2018-11-18 12:51:00 +0000
commite561e88b86dc1e52e1d11881e765a2dc270c673f (patch)
tree28ef1563fc605c0adb92d8c2a3b42a20caeb9faa /services
parent2e2b3d4b5ffca1a05cb05e1883c5dcd8f08fad2f (diff)
downloadtplink-energy-monitor-e561e88b86dc1e52e1d11881e765a2dc270c673f.tar.xz
tplink-energy-monitor-e561e88b86dc1e52e1d11881e765a2dc270c673f.zip
Skip RMS voltage calc for newer firmware versions
Fixes #7
Diffstat (limited to 'services')
-rw-r--r--services/data-fetcher.js22
1 files changed, 17 insertions, 5 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 {