node-red-contrib-energymeterplus 0.2.7 → 0.2.8

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.
@@ -4,14 +4,14 @@
4
4
  color: '#f3a108fe', <!-- Dutch Orange -->
5
5
  defaults: {
6
6
  name: {value:""},
7
- baselineDaily: {value:0},
8
- baselineWeekly: {value:0},
9
- baselineMonthly: {value:0},
10
- baselineYearly: {value:0},
11
- unitCost: {value:0.15},
12
- currency: {value:"USD"}, // NEW field
13
- filePath: {value:"/config/node_red/solargen_data.json"},
14
- inputUnit: {value:"kW"}
7
+ baselineDaily: {value:0, required:false},
8
+ baselineWeekly: {value:0, required:false},
9
+ baselineMonthly: {value:0, required:false},
10
+ baselineYearly: {value:0, required:false},
11
+ unitCost: {value:0.15, required:true},
12
+ currency: {value:"USD", required:true}, // NEW field
13
+ filePath: {value:"/config/node_red/solargen_data.json", required:false},
14
+ inputUnit: {value:"kW", required:true}
15
15
  },
16
16
  inputs:1,
17
17
  outputs:1,
@@ -19,12 +19,23 @@
19
19
  label: function() {
20
20
  return this.name || "energyMeterPlus";
21
21
  },
22
+ oneditprepare: function() {
23
+ // Nothing special here yet
24
+ },
22
25
  oneditsave: function() {
23
- // Cosmetic blanking: clear baseline fields in the editor UI after deploy
24
- $("#node-input-baselineDaily").val("");
25
- $("#node-input-baselineWeekly").val("");
26
- $("#node-input-baselineMonthly").val("");
27
- $("#node-input-baselineYearly").val("");
26
+ // When user clicks Done, send a one-time baseline message
27
+ var baselineMsg = {
28
+ topic: "applyBaseline",
29
+ nodeId: this.id, // include the nodeId!
30
+ payload: {
31
+ daily: Number($("#node-input-baselineDaily").val()) || 0,
32
+ weekly: Number($("#node-input-baselineWeekly").val()) || 0,
33
+ monthly: Number($("#node-input-baselineMonthly").val()) || 0,
34
+ yearly: Number($("#node-input-baselineYearly").val()) || 0
35
+ }
36
+ };
37
+ // Push message into runtime instantly
38
+ RED.comms.send("energyMeterPlus/applyBaseline", baselineMsg);
28
39
  }
29
40
  });
30
41
  </script>
@@ -2,6 +2,25 @@ const fs = require("fs");
2
2
  const path = require("path");
3
3
 
4
4
  module.exports = function(RED) {
5
+
6
+ // Listener for baseline messages from the editor
7
+ RED.comms.subscribe("energyMeterPlus/applyBaseline", function(baselineMsg) {
8
+ // baselineMsg should include nodeId so we know which instance to update
9
+ const nodeInstance = RED.nodes.getNode(baselineMsg.nodeId);
10
+ if (nodeInstance) {
11
+ let baseline = nodeInstance.context().get("baseline") || {
12
+ daily:0, weekly:0, monthly:0, yearly:0
13
+ };
14
+
15
+ baseline.daily = baselineMsg.payload.daily;
16
+ baseline.weekly = baselineMsg.payload.weekly;
17
+ baseline.monthly = baselineMsg.payload.monthly;
18
+ baseline.yearly = baselineMsg.payload.yearly;
19
+
20
+ nodeInstance.context().set("baseline", baseline);
21
+ }
22
+ });
23
+
5
24
  function EnergyMeterPlus(config) {
6
25
  RED.nodes.createNode(this, config);
7
26
  var node = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-energymeterplus",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
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",