node-red-contrib-energymeterplus 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/energyMeterPlus.js +11 -2
- package/package.json +1 -1
package/energyMeterPlus.js
CHANGED
|
@@ -24,7 +24,11 @@ module.exports = function(RED) {
|
|
|
24
24
|
daily:0, weekly:0, monthly:0, yearly:0
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// Rehydrate lastCheck from context
|
|
28
|
+
let lastCheck = node.context().get("lastCheck");
|
|
29
|
+
if (!(lastCheck instanceof Date)) {
|
|
30
|
+
lastCheck = new Date(lastCheck || Date.now());
|
|
31
|
+
}
|
|
28
32
|
|
|
29
33
|
function currencySymbol(code) {
|
|
30
34
|
switch (code) {
|
|
@@ -57,6 +61,11 @@ module.exports = function(RED) {
|
|
|
57
61
|
function checkRollover() {
|
|
58
62
|
let now = new Date();
|
|
59
63
|
|
|
64
|
+
// Ensure lastCheck is a Date
|
|
65
|
+
if (!(lastCheck instanceof Date)) {
|
|
66
|
+
lastCheck = new Date(lastCheck || Date.now());
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
if (now.getDate() !== lastCheck.getDate()) {
|
|
61
70
|
accumulated.daily = 0; baseline.daily = 0;
|
|
62
71
|
}
|
|
@@ -72,9 +81,9 @@ module.exports = function(RED) {
|
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
lastCheck = now;
|
|
84
|
+
node.context().set("lastCheck", lastCheck);
|
|
75
85
|
node.context().set("accumulated", accumulated);
|
|
76
86
|
node.context().set("baseline", baseline);
|
|
77
|
-
node.context().set("lastCheck", lastCheck);
|
|
78
87
|
}
|
|
79
88
|
setInterval(checkRollover, 60000);
|
|
80
89
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-energymeterplus",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "A custom Node-RED node that integrates power readings into energy totals with persistence and cost calculation.",
|
|
5
5
|
"author": "Arcfrankye",
|
|
6
6
|
"license": "MIT",
|