@bldgblocks/node-red-contrib-control 0.1.32 → 0.1.33

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.
Files changed (71) hide show
  1. package/nodes/accumulate-block.html +1 -1
  2. package/nodes/add-block.html +1 -1
  3. package/nodes/analog-switch-block.html +1 -1
  4. package/nodes/and-block.html +1 -1
  5. package/nodes/average-block.html +1 -1
  6. package/nodes/boolean-switch-block.html +1 -1
  7. package/nodes/boolean-to-number-block.html +1 -1
  8. package/nodes/cache-block.html +1 -1
  9. package/nodes/call-status-block.html +1 -1
  10. package/nodes/changeover-block.html +1 -1
  11. package/nodes/comment-block.html +1 -1
  12. package/nodes/compare-block.html +1 -1
  13. package/nodes/contextual-label-block.html +1 -1
  14. package/nodes/convert-block.html +1 -1
  15. package/nodes/count-block.html +2 -2
  16. package/nodes/delay-block.html +1 -1
  17. package/nodes/divide-block.html +1 -1
  18. package/nodes/edge-block.html +1 -1
  19. package/nodes/enum-switch-block.html +1 -1
  20. package/nodes/frequency-block.html +1 -1
  21. package/nodes/global-getter.html +34 -3
  22. package/nodes/global-getter.js +71 -45
  23. package/nodes/global-setter.html +21 -10
  24. package/nodes/global-setter.js +154 -79
  25. package/nodes/history-collector.html +283 -0
  26. package/nodes/history-collector.js +150 -0
  27. package/nodes/history-config.html +236 -0
  28. package/nodes/history-config.js +8 -0
  29. package/nodes/hysteresis-block.html +1 -1
  30. package/nodes/interpolate-block.html +1 -1
  31. package/nodes/latch-block.html +1 -1
  32. package/nodes/load-sequence-block.html +1 -1
  33. package/nodes/max-block.html +1 -1
  34. package/nodes/memory-block.html +1 -1
  35. package/nodes/min-block.html +1 -1
  36. package/nodes/minmax-block.html +1 -1
  37. package/nodes/modulo-block.html +1 -1
  38. package/nodes/multiply-block.html +1 -1
  39. package/nodes/negate-block.html +1 -1
  40. package/nodes/network-point-registry.html +86 -0
  41. package/nodes/network-point-registry.js +90 -0
  42. package/nodes/network-read.html +56 -0
  43. package/nodes/network-read.js +59 -0
  44. package/nodes/network-register.html +110 -0
  45. package/nodes/network-register.js +161 -0
  46. package/nodes/network-write.html +64 -0
  47. package/nodes/network-write.js +126 -0
  48. package/nodes/nullify-block.html +1 -1
  49. package/nodes/on-change-block.html +1 -1
  50. package/nodes/oneshot-block.html +1 -1
  51. package/nodes/or-block.html +1 -1
  52. package/nodes/pid-block.html +1 -1
  53. package/nodes/priority-block.html +1 -1
  54. package/nodes/rate-limit-block.html +2 -2
  55. package/nodes/rate-of-change-block.html +1 -1
  56. package/nodes/rate-of-change-block.js +5 -2
  57. package/nodes/round-block.html +6 -5
  58. package/nodes/round-block.js +5 -3
  59. package/nodes/saw-tooth-wave-block.html +2 -2
  60. package/nodes/scale-range-block.html +1 -1
  61. package/nodes/sine-wave-block.html +2 -2
  62. package/nodes/string-builder-block.html +1 -1
  63. package/nodes/subtract-block.html +1 -1
  64. package/nodes/thermistor-block.html +1 -1
  65. package/nodes/tick-tock-block.html +2 -2
  66. package/nodes/time-sequence-block.html +1 -1
  67. package/nodes/triangle-wave-block.html +2 -2
  68. package/nodes/tstat-block.html +1 -1
  69. package/nodes/units-block.html +8 -38
  70. package/nodes/units-block.js +3 -42
  71. package/package.json +11 -4
@@ -15,7 +15,7 @@
15
15
 
16
16
  <script type="text/javascript">
17
17
  RED.nodes.registerType("accumulate-block", {
18
- category: "control",
18
+ category: "bldgblocks control",
19
19
  color: "#301934",
20
20
  defaults: {
21
21
  name: { value: "" },
@@ -11,7 +11,7 @@
11
11
 
12
12
  <script type="text/javascript">
13
13
  RED.nodes.registerType("add-block", {
14
- category: "control",
14
+ category: "bldgblocks control",
15
15
  color: "#301934",
16
16
  defaults: {
17
17
  name: { value: "" },
@@ -13,7 +13,7 @@
13
13
  <!-- JavaScript Section: Registers the node and handles editor logic -->
14
14
  <script type="text/javascript">
15
15
  RED.nodes.registerType("analog-switch-block", {
16
- category: "control",
16
+ category: "bldgblocks control",
17
17
  color: "#301934",
18
18
  defaults: {
19
19
  name: { value: "" },
@@ -11,7 +11,7 @@
11
11
 
12
12
  <script type="text/javascript">
13
13
  RED.nodes.registerType("and-block", {
14
- category: "control",
14
+ category: "bldgblocks control",
15
15
  color: "#301934",
16
16
  defaults: {
17
17
  name: { value: "" },
@@ -21,7 +21,7 @@
21
21
 
22
22
  <script type="text/javascript">
23
23
  RED.nodes.registerType("average-block", {
24
- category: "control",
24
+ category: "bldgblocks control",
25
25
  color: "#301934",
26
26
  defaults: {
27
27
  name: { value: "" },
@@ -9,7 +9,7 @@
9
9
  <!-- JavaScript Section -->
10
10
  <script type="text/javascript">
11
11
  RED.nodes.registerType("boolean-switch-block", {
12
- category: "control",
12
+ category: "bldgblocks control",
13
13
  color: "#301934",
14
14
  defaults: {
15
15
  name: { value: "" },
@@ -13,7 +13,7 @@
13
13
  <!-- JavaScript Section -->
14
14
  <script type="text/javascript">
15
15
  RED.nodes.registerType("boolean-to-number-block", {
16
- category: "control",
16
+ category: "bldgblocks control",
17
17
  color: "#301934",
18
18
  defaults: {
19
19
  name: { value: "" },
@@ -13,7 +13,7 @@
13
13
  <!-- JavaScript Section: Registers the node and handles editor logic -->
14
14
  <script type="text/javascript">
15
15
  RED.nodes.registerType("cache-block", {
16
- category: "control",
16
+ category: "bldgblocks control",
17
17
  color: "#301934",
18
18
  defaults: {
19
19
  name: { value: "" },
@@ -33,7 +33,7 @@
33
33
  <!-- JavaScript Section: Registers the node and handles editor logic -->
34
34
  <script type="text/javascript">
35
35
  RED.nodes.registerType("call-status-block", {
36
- category: "control",
36
+ category: "bldgblocks control",
37
37
  color: "#301934",
38
38
  defaults: {
39
39
  name: { value: "" },
@@ -93,7 +93,7 @@
93
93
 
94
94
  <script type="text/javascript">
95
95
  RED.nodes.registerType("changeover-block", {
96
- category: "control",
96
+ category: "bldgblocks control",
97
97
  color: "#301934",
98
98
  defaults: {
99
99
  name: { value: "" },
@@ -19,7 +19,7 @@
19
19
 
20
20
  <script type="text/javascript">
21
21
  RED.nodes.registerType("comment-block", {
22
- category: "control",
22
+ category: "bldgblocks control",
23
23
  color: "#301934",
24
24
  defaults: {
25
25
  name: { value: "comment" },
@@ -13,7 +13,7 @@
13
13
  <!-- JavaScript Section: Registers the node and handles editor logic -->
14
14
  <script type="text/javascript">
15
15
  RED.nodes.registerType("compare-block", {
16
- category: "control",
16
+ category: "bldgblocks control",
17
17
  color: "#301934",
18
18
  defaults: {
19
19
  name: { value: "" },
@@ -15,7 +15,7 @@
15
15
 
16
16
  <script type="text/javascript">
17
17
  RED.nodes.registerType("contextual-label-block", {
18
- category: "control",
18
+ category: "bldgblocks control",
19
19
  color: "#301934",
20
20
  defaults: {
21
21
  name: { value: "" },
@@ -58,7 +58,7 @@
58
58
 
59
59
  <script type="text/javascript">
60
60
  RED.nodes.registerType("convert-block", {
61
- category: "control",
61
+ category: "bldgblocks control",
62
62
  color: "#301934",
63
63
  defaults: {
64
64
  name: { value: "" },
@@ -9,7 +9,7 @@
9
9
  <!-- JavaScript Section: Registers the node and handles editor logic -->
10
10
  <script type="text/javascript">
11
11
  RED.nodes.registerType("count-block", {
12
- category: "control",
12
+ category: "bldgblocks control",
13
13
  color: "#301934",
14
14
  defaults: {
15
15
  name: { value: "" }
@@ -18,7 +18,7 @@
18
18
  outputs: 1,
19
19
  inputLabels: ["input"],
20
20
  outputLabels: ["count"],
21
- icon: "font-awesome/fa-tally",
21
+ icon: "font-awesome/fa-calculator",
22
22
  paletteLabel: "count",
23
23
  label: function() {
24
24
  return this.name || "count";
@@ -33,7 +33,7 @@
33
33
  <!-- JavaScript Section: Registers the node and handles editor logic -->
34
34
  <script type="text/javascript">
35
35
  RED.nodes.registerType("delay-block", {
36
- category: "control",
36
+ category: "bldgblocks control",
37
37
  color: "#301934",
38
38
  defaults: {
39
39
  name: { value: "" },
@@ -11,7 +11,7 @@
11
11
 
12
12
  <script type="text/javascript">
13
13
  RED.nodes.registerType("divide-block", {
14
- category: "control",
14
+ category: "bldgblocks control",
15
15
  color: "#301934",
16
16
  defaults: {
17
17
  name: { value: "" },
@@ -16,7 +16,7 @@
16
16
  <!-- JavaScript Section -->
17
17
  <script type="text/javascript">
18
18
  RED.nodes.registerType("edge-block", {
19
- category: "control",
19
+ category: "bldgblocks control",
20
20
  color: "#301934",
21
21
  defaults: {
22
22
  name: { value: "" },
@@ -31,7 +31,7 @@
31
31
 
32
32
  <script type="text/javascript">
33
33
  RED.nodes.registerType("enum-switch-block", {
34
- category: "control",
34
+ category: "bldgblocks control",
35
35
  color: "#301934",
36
36
  defaults: {
37
37
  name: { value: "" },
@@ -9,7 +9,7 @@
9
9
  <!-- JavaScript Section: Registers the node and handles editor logic -->
10
10
  <script type="text/javascript">
11
11
  RED.nodes.registerType("frequency-block", {
12
- category: "control",
12
+ category: "bldgblocks control",
13
13
  color: "#301934",
14
14
  defaults: {
15
15
  name: { value: "" }
@@ -26,7 +26,7 @@
26
26
  </div>
27
27
 
28
28
  <div class="form-row">
29
- <label for="node-input-detail"><i class="fa fa-bolt"></i> Trigger</label>
29
+ <label for="node-input-detail"><i class="fa fa-book"></i> Detail</label>
30
30
  <select id="node-input-detail" style="width: 70%;">
31
31
  <option value="getValue">Get Simple Value</option>
32
32
  <option value="getObject">Get Full Object</option>
@@ -40,7 +40,7 @@
40
40
 
41
41
  <script type="text/javascript">
42
42
  RED.nodes.registerType('global-getter', {
43
- category: 'control',
43
+ category: "bldgblocks control",
44
44
  color: '#3FADB5',
45
45
  defaults: {
46
46
  name: { value: "" },
@@ -56,7 +56,7 @@
56
56
  if (this.targetNode) {
57
57
  const target = RED.nodes.node(this.targetNode);
58
58
  if (target) {
59
- let lbl = target.path || target.name;
59
+ let lbl = target.name || target.path;
60
60
  if(lbl && lbl.startsWith("#") && lbl.includes(":")) {
61
61
  lbl = lbl.substring(lbl.indexOf(":") + 1);
62
62
  }
@@ -99,3 +99,34 @@
99
99
  }
100
100
  });
101
101
  </script>
102
+
103
+ <!-- Help Section -->
104
+ <script type="text/markdown" data-help-name="global-setter">
105
+ Manage a global variable in a repeatable way.
106
+
107
+ ### Inputs
108
+ Retreived object will overwrite msg.
109
+
110
+ ### Outputs
111
+ : payload (object) : The stored object with values and metadata.
112
+
113
+ ### Details
114
+ Global variables are meant to be retrieved in other places, this necessarily means managing the same string in multiple places.
115
+
116
+ This node allows you to get a global variable anywhere from one source, while supporting rename and deletion.
117
+
118
+ The source can be found using the search button. The payload property can be specified and can be set to only the value for chaining.
119
+
120
+ Reactive updates means every time the source is updated those nodes will receive the new value via event.
121
+
122
+ ### Status
123
+ - Green (dot): Configuration update
124
+ - Blue (dot): State changed
125
+ - Blue (ring): State unchanged
126
+ - Red (ring): Error
127
+ - Yellow (ring): Warning
128
+
129
+ ### References
130
+ - [Node-RED Documentation](https://nodered.org/docs/)
131
+ - [GitHub Repository](https://github.com/BldgBlocks/node-red-contrib-buildingblocks-control.git)
132
+ </script>
@@ -6,44 +6,42 @@ module.exports = function(RED) {
6
6
  node.outputProperty = config.outputProperty || "payload";
7
7
  node.updates = config.updates;
8
8
  node.detail = config.detail;
9
-
9
+
10
10
  let setterNode = null;
11
- let retryInterval = null;
11
+ let retryAction = null;
12
+ let healthCheckAction = null;
12
13
  let updateListener = null;
13
14
  let retryCount = 0;
14
15
  const retryDelays = [0, 100, 500, 1000, 2000, 4000, 8000, 16000];
15
16
  const maxRetries = retryDelays.length - 1;
16
17
 
17
- // --- HELPER: Process Wrapper and Send Msg ---
18
+ // --- Process Wrapper and Send Msg ---
18
19
  function sendValue(storedObject, msgToReuse) {
19
20
  const msg = msgToReuse || {};
20
21
 
21
22
  if (storedObject !== undefined && storedObject !== null) {
22
23
 
23
24
  // CHECK: Is this our Wrapper Format? (Created by Global Setter)
24
- if (storedObject && typeof storedObject === 'object' && storedObject.hasOwnProperty('value')) {
25
-
26
- // 1. Separate the Value from everything else (Rest operator)
27
- // 'attributes' will contain: priority, units, metadata, topic, etc.
28
- const { value, ...attributes } = storedObject;
25
+ if (storedObject && typeof storedObject === 'object' && storedObject.hasOwnProperty('value')) {
29
26
 
30
- // 2. Set the Main Output (e.g. msg.payload = 75)
31
- RED.util.setMessageProperty(msg, node.outputProperty, value);
32
-
33
- // 3. Merge all attributes onto the msg root
27
+ // Merge all attributes onto the msg root
34
28
  // This automatically handles priority, units, metadata, and any future fields
35
29
  if (node.detail === "getObject") {
36
- Object.assign(msg, attributes);
30
+ Object.assign(msg, storedObject);
37
31
  }
38
32
 
33
+ // Set the Main Output (e.g. msg.payload = 75)
34
+ RED.util.setMessageProperty(msg, node.outputProperty, storedObject.value);
35
+
39
36
  } else {
40
- // Handle Legacy/Raw values (not created by your Setter)
37
+ // Handle Legacy/Raw values (not created by Setter)
41
38
  RED.util.setMessageProperty(msg, node.outputProperty, storedObject);
42
39
  msg.metadata = { path: setterNode ? setterNode.varName : "unknown", legacy: true };
43
40
  }
44
41
 
45
- // Visual Status
46
- const valDisplay = RED.util.getMessageProperty(msg, node.outputProperty);
42
+ // Update Status
43
+ let valDisplay = RED.util.getMessageProperty(msg, node.outputProperty);
44
+ valDisplay = typeof valDisplay === "number" ? valDisplay : valDisplay;
47
45
  node.status({ fill: "blue", shape: "dot", text: `get: ${valDisplay}` });
48
46
 
49
47
  node.send(msg);
@@ -53,10 +51,12 @@ module.exports = function(RED) {
53
51
  }
54
52
  }
55
53
 
56
- // --- HELPER: Manage Event Subscription ---
54
+ // --- Manage Event Subscription ---
57
55
  function establishListener() {
56
+ // Look for source node
58
57
  setterNode = RED.nodes.getNode(node.targetNodeId);
59
58
 
59
+ // If found, subscribe
60
60
  if (setterNode && setterNode.varName && node.updates === 'always') {
61
61
  if (updateListener) {
62
62
  // Remove existing listener if we're retrying
@@ -72,9 +72,9 @@ module.exports = function(RED) {
72
72
  RED.events.on("bldgblocks-global-update", updateListener);
73
73
 
74
74
  // Clear retry interval once successful
75
- if (retryInterval) {
76
- clearInterval(retryInterval);
77
- retryInterval = null;
75
+ if (retryAction) {
76
+ clearInterval(retryAction);
77
+ retryAction = null;
78
78
  }
79
79
 
80
80
  node.status({ fill: "green", shape: "dot", text: "Connected" });
@@ -83,13 +83,55 @@ module.exports = function(RED) {
83
83
  return false;
84
84
  }
85
85
 
86
+ // --- Maintain event subscription ---
87
+ function startHealthCheck() {
88
+ const healthCheckAction = () => {
89
+ const listeners = RED.events.listeners("bldgblocks-global-update");
90
+ const hasOurListener = listeners.includes(updateListener);
91
+
92
+ if (!hasOurListener) {
93
+ node.warn("Event listener lost, reconnecting...");
94
+ if (establishListener()) {
95
+ node.status({ fill: "green", shape: "dot", text: "Reconnected" });
96
+ }
97
+ }
98
+
99
+ // Schedule next health check regardless of outcome
100
+ setTimeout(healthCheckAction, 30000);
101
+ };
102
+ // Inital start
103
+ setTimeout(healthCheckAction, 30000);
104
+ }
105
+
106
+ function subscribeWithRetry() {
107
+ // Recursive retry
108
+ retryAction = () => {
109
+ if (retryCount >= maxRetries) {
110
+ node.error("Failed to connect to setter node after multiple attempts");
111
+ node.status({ fill: "red", shape: "ring", text: "Connection failed" });
112
+ return;
113
+ }
114
+
115
+ if (establishListener()) {
116
+ retryCount = 0;
117
+ return; // Success
118
+ }
119
+
120
+ retryCount++;
121
+ setTimeout(retryAction, retryDelays[Math.min(retryCount, maxRetries - 1)]);
122
+ };
123
+
124
+ setTimeout(retryAction, retryDelays[0]);
125
+ }
126
+
86
127
  // --- HANDLE MANUAL INPUT ---
87
128
  node.on('input', function(msg, send, done) {
88
129
  send = send || function() { node.send.apply(node, arguments); };
89
130
 
131
+ setterNode ??= RED.nodes.getNode(node.targetNodeId);
132
+
90
133
  if (setterNode && setterNode.varName) {
91
- const globalContext = node.context().global;
92
- const storedObject = globalContext.get(setterNode.varName, setterNode.storeName);
134
+ const storedObject = node.context().global.get(setterNode.varName, setterNode.storeName);
93
135
  sendValue(storedObject, msg);
94
136
  } else {
95
137
  node.warn("Source node not found or not configured.");
@@ -101,33 +143,17 @@ module.exports = function(RED) {
101
143
 
102
144
  // --- HANDLE REACTIVE UPDATES ---
103
145
  if (node.updates === 'always') {
104
- if (!establishListener()) {
105
- // Recursive retry
106
- const retry = () => {
107
- if (retryCount >= maxRetries) {
108
- node.error("Failed to connect to setter node after multiple attempts");
109
- node.status({ fill: "red", shape: "ring", text: "Connection failed" });
110
- return;
111
- }
112
-
113
- if (establishListener()) {
114
- retryCount = 0;
115
- return; // Success
116
- }
117
-
118
- retryCount++;
119
- setTimeout(retry, retryDelays[Math.min(retryCount, maxRetries - 1)]);
120
- };
121
-
122
- // Try immediately
123
- setTimeout(retry, retryDelays[0]);
124
- }
146
+ subscribeWithRetry();
147
+ startHealthCheck();
125
148
  }
126
149
 
127
150
  // --- CLEANUP ---
128
151
  node.on('close', function(removed, done) {
129
- if (retryInterval) {
130
- clearInterval(retryInterval);
152
+ if (healthCheckAction) {
153
+ clearInterval(healthCheckAction);
154
+ }
155
+ if (retryAction) {
156
+ clearInterval(retryAction);
131
157
  }
132
158
  if (removed && updateListener) {
133
159
  RED.events.removeListener("bldgblocks-global-update", updateListener);
@@ -20,45 +20,56 @@
20
20
  <hr>
21
21
 
22
22
  <div class="form-row">
23
- <label for="node-input-defaultValue" title="Static default value to ensure one exists. You may write to default through message configuration."><i class="fa fa-undo"></i> Default</label>
23
+ <label for="node-input-defaultValue" title="Manual default value to ensure one always exists. You may write to default through message configuration but may not set it to null."><i class="fa fa-undo"></i> Default</label>
24
24
  <input type="text" id="node-input-defaultValue" placeholder="e.g. 0 or false">
25
+ <input type="hidden" id="node-input-defaultValueType">
25
26
  </div>
26
27
 
27
28
  <div class="form-tips">
28
- <b>Note:</b> This node writes to the selected <b>Priority Level</b>. The actual Global Variable value will be the highest active priority.
29
+ <b>Note:</b> This node writes to the selected <b>Priority</b>, manually, by msg or flow. The actual Global Variable value will be the highest active priority.
29
30
  </div>
30
31
  </script>
31
32
 
32
33
  <script type="text/javascript">
33
34
  RED.nodes.registerType('global-setter', {
34
- category: 'control',
35
+ category: "bldgblocks control",
35
36
  color: '#E2D96E',
36
37
  defaults: {
37
38
  name: { value: "" },
38
39
  path: { value: "", required: true },
39
40
  property: { value: "payload", required: true },
40
41
  defaultValue: { value: "", required: true },
41
- writePriority: { value: "16", required: true },
42
+ defaultValueType: { value: "num", required: true },
43
+ writePriority: { value: "default", required: true },
42
44
  writePriorityType: { value: "dropdown" }
43
45
  },
44
46
  inputs: 1,
45
47
  outputs: 1,
46
48
  icon: "font-awesome/fa-align-right",
47
49
  label: function() {
48
- let lbl = this.path;
49
- if (lbl && lbl.startsWith("#") && lbl.includes(":")) {
50
- lbl = lbl.substring(lbl.indexOf(":") + 1);
50
+ let lbl = this.name || this.path;
51
+ if (lbl) {
52
+ if (lbl && lbl.startsWith("#") && lbl.includes(":")) {
53
+ lbl = lbl.substring(lbl.indexOf(":") + 1);
54
+ }
55
+ return "set: " + lbl;
51
56
  }
52
- return this.name || "set: " + lbl || "global set";
57
+ return this.name || "global set";
53
58
  },
54
59
  paletteLabel: "global set",
55
60
  oneditprepare: function() {
61
+ const node = this;
62
+
56
63
  // These are read as strings not evaluated typed-inputs.
57
64
  $("#node-input-path").typedInput({ types: ['global'] });
58
65
  // getMessageProperty handles msg access on the incoming message at the specified path.
59
66
  $("#node-input-property").typedInput({ types: ['msg'] });
60
67
  // Default for the default value, meaning it should only be manually set. You can still pass default values through messages.
61
- $("#node-input-defaultValue").typedInput({ types: ['str','num','bool'] });
68
+ $("#node-input-defaultValue").typedInput({
69
+ default: "num",
70
+ types: ["str", "num", "bool", "json"],
71
+ typeField: "#node-input-defaultValueType"
72
+ }).typedInput("type", node.defaultValueType || "num").typedInput("value", node.defaultValue);
62
73
 
63
74
  $("#node-input-writePriority").typedInput({
64
75
  default: "dropdown",
@@ -80,7 +91,7 @@
80
91
  { value: "13", label: "13"},
81
92
  { value: "14", label: "14"},
82
93
  { value: "15", label: "15"},
83
- { value: "16", label: "16 (Schedule/Logic)"},
94
+ { value: "16", label: "16 (Network Logic)"},
84
95
  { value: "default", label: "default (fallback)"},
85
96
  ]
86
97
  }, "msg", "flow"],