@bldgblocks/node-red-contrib-control 0.1.24 → 0.1.26
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/README.md +1 -1
- package/nodes/on-change-block.html +1 -1
- package/nodes/on-change-block.js +26 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ The help section of every node describes the expected msg.context (data tag) for
|
|
|
32
32
|
An 'and' block set to 4 slots must recieve `true` values on each inX at some point to evaluate to a `true` output. Where as, an 'or' block set to 4 inputs could have any input trigger a `true` evaluation. However, a remaining `true` would prevent evaluating to `false`. So the flow may look like 4 small tagging nodes configured in1,in2,in3,in4 connecting to the 'and' block and just wiring your branches of logic to those inputs. You can also negate or have multiple connected to an input and you can watch as each comes in to evaluate. Just try to keep it clean.
|
|
33
33
|
|
|
34
34
|
## Install
|
|
35
|
-
##### Via NodeRED Palette Manager
|
|
35
|
+
##### Via NodeRED Palette Manager
|
|
36
36
|
|
|
37
37
|
Search for the package name and add to your project.
|
|
38
38
|
|
|
@@ -46,7 +46,7 @@ Filters redundant messages based on value changes and a configurable period.
|
|
|
46
46
|
|
|
47
47
|
### Inputs
|
|
48
48
|
: payload (any) : Input value to compare.
|
|
49
|
-
: context (string, optional) : Configures period (`"period"`) or queries state (`"status"`).
|
|
49
|
+
: context (string, optional) : Configures period (`"period"`) or queries state (`"status"`).
|
|
50
50
|
: payload (number | any, for `context`) : Non-negative number for `"period"` (ms), any for `"status"`.
|
|
51
51
|
|
|
52
52
|
### Outputs
|
package/nodes/on-change-block.js
CHANGED
|
@@ -9,13 +9,12 @@ module.exports = function(RED) {
|
|
|
9
9
|
node.runtime = {
|
|
10
10
|
name: config.name,
|
|
11
11
|
lastValue: null,
|
|
12
|
-
blockTimer: null
|
|
13
|
-
pendingMsg: null
|
|
12
|
+
blockTimer: null
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
// Evaluate typed-input properties
|
|
17
16
|
try {
|
|
18
|
-
node.runtime.period = RED.util.evaluateNodeProperty(
|
|
17
|
+
node.runtime.period = RED.util.evaluateNodeProperty( config.period, config.periodType, node );
|
|
19
18
|
node.runtime.period = parseFloat(node.runtime.period);
|
|
20
19
|
} catch (err) {
|
|
21
20
|
node.status({ fill: "red", shape: "ring", text: "error evaluating properties" });
|
|
@@ -45,14 +44,13 @@ module.exports = function(RED) {
|
|
|
45
44
|
|
|
46
45
|
// Acceptable fallbacks
|
|
47
46
|
if (isNaN(node.runtime.period) || node.runtime.period < 0) {
|
|
48
|
-
node.runtime.period =
|
|
47
|
+
node.runtime.period = config.period;
|
|
49
48
|
node.status({ fill: "red", shape: "ring", text: "invalid period, using 0" });
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
// Handle context updates
|
|
53
52
|
if (msg.hasOwnProperty("context") && typeof msg.context === "string") {
|
|
54
|
-
|
|
55
|
-
if (contextLower === "period") {
|
|
53
|
+
if (msg.context === "period") {
|
|
56
54
|
if (!msg.hasOwnProperty("payload")) {
|
|
57
55
|
node.status({ fill: "red", shape: "ring", text: "missing payload for period" });
|
|
58
56
|
if (done) done();
|
|
@@ -74,7 +72,7 @@ module.exports = function(RED) {
|
|
|
74
72
|
if (done) done();
|
|
75
73
|
return;
|
|
76
74
|
}
|
|
77
|
-
if (
|
|
75
|
+
if (msg.context === "status") {
|
|
78
76
|
send({
|
|
79
77
|
payload: {
|
|
80
78
|
period: node.runtime.period,
|
|
@@ -114,9 +112,8 @@ module.exports = function(RED) {
|
|
|
114
112
|
return false;
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
//
|
|
115
|
+
// Block if in filter period
|
|
118
116
|
if (node.runtime.blockTimer) {
|
|
119
|
-
node.runtime.pendingMsg = RED.util.cloneMessage(msg);
|
|
120
117
|
node.status({
|
|
121
118
|
fill: "blue",
|
|
122
119
|
shape: "ring",
|
|
@@ -126,49 +123,27 @@ module.exports = function(RED) {
|
|
|
126
123
|
return;
|
|
127
124
|
}
|
|
128
125
|
|
|
129
|
-
//
|
|
130
|
-
if (
|
|
131
|
-
node.runtime.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
shape: "dot",
|
|
135
|
-
text: `out: ${JSON.stringify(currentValue).slice(0, 20)}`
|
|
136
|
-
});
|
|
137
|
-
send(msg);
|
|
138
|
-
|
|
139
|
-
// Start filter period if applicable
|
|
140
|
-
if (node.runtime.period > 0) {
|
|
141
|
-
node.runtime.blockTimer = setTimeout(() => {
|
|
142
|
-
node.runtime.blockTimer = null;
|
|
143
|
-
if (node.runtime.pendingMsg) {
|
|
144
|
-
const pendingValue = node.runtime.pendingMsg.payload;
|
|
145
|
-
if (!isEqual(pendingValue, node.runtime.lastValue)) {
|
|
146
|
-
node.runtime.lastValue = RED.util.cloneMessage(pendingValue);
|
|
147
|
-
node.status({
|
|
148
|
-
fill: "blue",
|
|
149
|
-
shape: "dot",
|
|
150
|
-
text: `out: ${JSON.stringify(pendingValue).slice(0, 20)}`
|
|
151
|
-
});
|
|
152
|
-
send(node.runtime.pendingMsg);
|
|
153
|
-
} else {
|
|
154
|
-
node.status({
|
|
155
|
-
fill: "blue",
|
|
156
|
-
shape: "ring",
|
|
157
|
-
text: `Filter period expired`
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
node.runtime.pendingMsg = null;
|
|
161
|
-
} else {
|
|
162
|
-
node.status({});
|
|
163
|
-
}
|
|
164
|
-
}, node.runtime.period);
|
|
126
|
+
// period === 0 means only ever on change, not equal outside of filter period sends an update message
|
|
127
|
+
if (isEqual(currentValue, node.runtime.lastValue)) {
|
|
128
|
+
if (node.runtime.period === 0) {
|
|
129
|
+
if (done) done();
|
|
130
|
+
return;
|
|
165
131
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
node.runtime.lastValue = currentValue;
|
|
135
|
+
send(msg);
|
|
136
|
+
|
|
137
|
+
// Start filter period if applicable
|
|
138
|
+
if (node.runtime.period > 0) {
|
|
139
|
+
node.runtime.blockTimer = setTimeout(() => {
|
|
140
|
+
node.runtime.blockTimer = null;
|
|
141
|
+
node.status({
|
|
142
|
+
fill: "blue",
|
|
143
|
+
shape: "ring",
|
|
144
|
+
text: `Filter period expired`
|
|
145
|
+
});
|
|
146
|
+
}, node.runtime.period);
|
|
172
147
|
}
|
|
173
148
|
|
|
174
149
|
if (done) done();
|
package/package.json
CHANGED