@mschaeffler/node-red-logic 0.7.2 → 0.9.0

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/logic_and.html CHANGED
@@ -8,7 +8,8 @@
8
8
  property:{value:"payload", required:true},
9
9
  minData:{value:"1", required:true, validate:function(v){
10
10
  return v!=='' && !isNaN(v) && Number(v)>0;
11
- }}
11
+ }},
12
+ filter:{value:false}
12
13
  },
13
14
  inputs:1,
14
15
  outputs:1,
@@ -49,6 +50,10 @@
49
50
  <label for="node-input-minData"><i class="fa fa-tag"></i> min. Data</label>
50
51
  <input type="text" id="node-input-minData">
51
52
  </div>
53
+ <div class="form-row">
54
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
55
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
56
+ </div>
52
57
  </script>
53
58
 
54
59
  <script type="text/html" data-help-name="and">
package/logic_and.js CHANGED
@@ -9,6 +9,8 @@ module.exports = function(RED) {
9
9
  this.topic = config.topic;
10
10
  this.property = config.property || "payload";
11
11
  this.minData = Number( config.minData );
12
+ this.filter = Boolean( config.filter );
13
+ this.last = null;
12
14
 
13
15
  node.on('input', function(msg,send,done) {
14
16
  if( msg.invalid )
@@ -45,8 +47,26 @@ module.exports = function(RED) {
45
47
 
46
48
  if( msg.count >= node.minData )
47
49
  {
48
- node.status( msg.payload );
49
- send( msg );
50
+ let status = { text:msg.payload };
51
+ if( node.filter )
52
+ {
53
+ status.shape = "dot";
54
+ if( msg.payload !== node.last )
55
+ {
56
+ node.last = msg.payload;
57
+ status.fill = "green";
58
+ send( msg );
59
+ }
60
+ else
61
+ {
62
+ status.fill = "gray";
63
+ }
64
+ }
65
+ else
66
+ {
67
+ send( msg );
68
+ }
69
+ node.status( status );
50
70
  }
51
71
  else
52
72
  {
package/logic_bool.html CHANGED
@@ -5,7 +5,8 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
- showState:{value:false}
8
+ showState:{value:false},
9
+ filter:{value:false}
9
10
  },
10
11
  inputs:1,
11
12
  outputs:1,
@@ -43,6 +44,10 @@
43
44
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
44
45
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
45
46
  </div>
47
+ <div class="form-row">
48
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
49
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
50
+ </div>
46
51
  </script>
47
52
 
48
53
  <script type="text/html" data-help-name="tobool">
package/logic_bool.js CHANGED
@@ -5,8 +5,10 @@ module.exports = function(RED) {
5
5
  RED.nodes.createNode(this,config);
6
6
  //this.config = config;
7
7
  var node = this;
8
- this.property = config.property || "payload";
8
+ this.property = config.property || "payload";
9
9
  this.showState = config.showState;
10
+ this.filter = Boolean( config.filter );
11
+ this.last = null;
10
12
 
11
13
  node.on('input', function(msg,send,done) {
12
14
  if( msg.invalid )
@@ -15,21 +17,32 @@ module.exports = function(RED) {
15
17
  return null;
16
18
  }
17
19
  msg.payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
20
+ let status = { text:msg.payload ?? "error" };
18
21
  if( msg.payload !== null )
19
22
  {
20
- if( node.showState )
23
+ if( node.filter )
21
24
  {
22
- node.status( msg.payload );
25
+ status.shape = "dot";
26
+ if( msg.payload !== node.last )
27
+ {
28
+ node.last = msg.payload;
29
+ status.fill = "green";
30
+ send( msg );
31
+ }
32
+ else
33
+ {
34
+ status.fill = "gray";
35
+ }
23
36
  }
24
- send( msg );
25
- }
26
- else
27
- {
28
- if( node.showState )
37
+ else
29
38
  {
30
- node.status( "error" );
39
+ send( msg );
31
40
  }
32
41
  }
42
+ if( node.showState )
43
+ {
44
+ node.status( status );
45
+ }
33
46
  done();
34
47
  });
35
48
  }
package/logic_not.html ADDED
@@ -0,0 +1,97 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('not',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ showState:{value:false},
9
+ filter:{value:false}
10
+ },
11
+ inputs:1,
12
+ outputs:1,
13
+ icon: "font-awesome/fa-exclamation",
14
+ label: function() {
15
+ return this.name||"not";
16
+ },
17
+ labelStyle: function() {
18
+ return this.name?"node_label_italic":"";
19
+ },
20
+ paletteLabel: "not",
21
+ inputLabels: 'input',
22
+ outputLabels: 'boolean',
23
+ oneditprepare: function() {
24
+ $("#node-input-property").typedInput({
25
+ type:"msg",
26
+ types:["msg"],
27
+ typeField: "#node-input-property-type"
28
+ })
29
+ }
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="not">
34
+ <div class="form-row">
35
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
36
+ <input type="text" id="node-input-name" placeholder="Name">
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
+ <input type="text" id="node-input-property">
41
+ <input type="hidden" id="node-input-property-type">
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
45
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
49
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
50
+ </div>
51
+ </script>
52
+
53
+ <script type="text/html" data-help-name="not">
54
+
55
+ <p>Inverts the boolean value.</p>
56
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
57
+
58
+ <table>
59
+ <tr> <th>type</th> <th>input</th> <th>output</th> </tr>
60
+ <tr> <td>boolean</td> <td>false</td> <td>false</td> </tr>
61
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
62
+ <tr> <td>number</td> <td>0</td> <td>false</td> </tr>
63
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
64
+ <tr> <td>string</td> <td>false</td> <td>false</td> </tr>
65
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
66
+ <tr> <td></td> <td>0</td> <td>false</td> </tr>
67
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
68
+ <tr> <td></td> <td>off</td> <td>false</td> </tr>
69
+ <tr> <td></td> <td>on</td> <td>true</td> </tr>
70
+ </table>
71
+
72
+ <h3>Input</h3>
73
+
74
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
75
+
76
+ <dl class="message-properties">
77
+ <dt>payload <span class="property-type"></span></dt>
78
+ <dd> input value.</dd>
79
+ </dl>
80
+
81
+ <h3>Output</h3>
82
+
83
+ <dl class="message-properties">
84
+ <dt>payload <span class="property-type">boolean</span></dt>
85
+ <dd> bool value of payload.</dd>
86
+ </dl>
87
+
88
+ <h3>Parameter</h3>
89
+
90
+ <dl class="message-properties">
91
+ <dt>Property <span class="property-type">string</span></dt>
92
+ <dd> defines the message property to be used as payload.</dd>
93
+ <dt>Status <span class="property-type">boolean</span></dt>
94
+ <dd> shows the actual value as a node status.</dd>
95
+ </dl>
96
+
97
+ </script>
package/logic_not.js ADDED
@@ -0,0 +1,51 @@
1
+ module.exports = function(RED) {
2
+ var tools = require('./tools.js');
3
+
4
+ function NotNode(config) {
5
+ RED.nodes.createNode(this,config);
6
+ //this.config = config;
7
+ var node = this;
8
+ this.property = config.property || "payload";
9
+ this.showState = config.showState;
10
+ this.filter = Boolean( config.filter );
11
+ this.last = null;
12
+
13
+ node.on('input', function(msg,send,done) {
14
+ if( msg.invalid )
15
+ {
16
+ done();
17
+ return null;
18
+ }
19
+ msg.payload = ! tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
20
+ let status = { text:msg.payload ?? "error" };
21
+ if( msg.payload !== null )
22
+ {
23
+ if( node.filter )
24
+ {
25
+ status.shape = "dot";
26
+ if( msg.payload !== node.last )
27
+ {
28
+ node.last = msg.payload;
29
+ status.fill = "green";
30
+ send( msg );
31
+ }
32
+ else
33
+ {
34
+ status.fill = "gray";
35
+ }
36
+ }
37
+ else
38
+ {
39
+ send( msg );
40
+ }
41
+ }
42
+ if( node.showState )
43
+ {
44
+ node.status( status );
45
+ }
46
+ done();
47
+ });
48
+ }
49
+
50
+ RED.nodes.registerType("not",NotNode);
51
+ }
package/logic_or.html CHANGED
@@ -8,7 +8,8 @@
8
8
  property:{value:"payload", required:true},
9
9
  minData:{value:"1", required:true, validate:function(v){
10
10
  return v!=='' && !isNaN(v) && Number(v)>0;
11
- }}
11
+ }},
12
+ filter:{value:false}
12
13
  },
13
14
  inputs:1,
14
15
  outputs:1,
@@ -49,6 +50,10 @@
49
50
  <label for="node-input-minData"><i class="fa fa-tag"></i> min. Data</label>
50
51
  <input type="text" id="node-input-minData">
51
52
  </div>
53
+ <div class="form-row">
54
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
55
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
56
+ </div>
52
57
  </script>
53
58
 
54
59
  <script type="text/html" data-help-name="or">
package/logic_or.js CHANGED
@@ -9,6 +9,8 @@ module.exports = function(RED) {
9
9
  this.topic = config.topic;
10
10
  this.property = config.property || "payload";
11
11
  this.minData = Number( config.minData );
12
+ this.filter = Boolean( config.filter );
13
+ this.last = null;
12
14
 
13
15
  node.on('input', function(msg,send,done) {
14
16
  if( msg.invalid )
@@ -45,8 +47,26 @@ module.exports = function(RED) {
45
47
 
46
48
  if( msg.count >= node.minData )
47
49
  {
48
- node.status( msg.payload );
49
- send( msg );
50
+ let status = { text:msg.payload };
51
+ if( node.filter )
52
+ {
53
+ status.shape = "dot";
54
+ if( msg.payload !== node.last )
55
+ {
56
+ node.last = msg.payload;
57
+ status.fill = "green";
58
+ send( msg );
59
+ }
60
+ else
61
+ {
62
+ status.fill = "gray";
63
+ }
64
+ }
65
+ else
66
+ {
67
+ send( msg );
68
+ }
69
+ node.status( status );
50
70
  }
51
71
  else
52
72
  {
@@ -0,0 +1,83 @@
1
+ #<script type="text/javascript">
2
+ RED.nodes.registerType('negate',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ showState:{value:false},
9
+ filter:{value:false}
10
+ },
11
+ inputs:1,
12
+ outputs:1,
13
+ icon: "font-awesome/fa-minus",
14
+ label: function() {
15
+ return this.name||"minus";
16
+ },
17
+ labelStyle: function() {
18
+ return this.name?"node_label_italic":"";
19
+ },
20
+ paletteLabel: "minus",
21
+ inputLabels: 'input',
22
+ outputLabels: 'number',
23
+ oneditprepare: function() {
24
+ $("#node-input-property").typedInput({
25
+ type:"msg",
26
+ types:["msg"],
27
+ typeField: "#node-input-property-type"
28
+ })
29
+ }
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="negate">
34
+ <div class="form-row">
35
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
36
+ <input type="text" id="node-input-name" placeholder="Name">
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
+ <input type="text" id="node-input-property">
41
+ <input type="hidden" id="node-input-property-type">
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
45
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
49
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
50
+ </div>
51
+ </script>
52
+
53
+ <script type="text/html" data-help-name="negate">
54
+
55
+ <p>negates the payload.</p>
56
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
57
+
58
+ <h3>Input</h3>
59
+
60
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
61
+
62
+ <dl class="message-properties">
63
+ <dt>payload <span class="property-type"></span></dt>
64
+ <dd> input value.</dd>
65
+ </dl>
66
+
67
+ <h3>Output</h3>
68
+
69
+ <dl class="message-properties">
70
+ <dt>payload <span class="property-type">number</span></dt>
71
+ <dd> number value of payload.</dd>
72
+ </dl>
73
+
74
+ <h3>Parameter</h3>
75
+
76
+ <dl class="message-properties">
77
+ <dt>Property <span class="property-type">string</span></dt>
78
+ <dd> defines the message property to be used as payload.</dd>
79
+ <dt>Status <span class="property-type">boolean</span></dt>
80
+ <dd> shows the actual value as a node status.</dd>
81
+ </dl>
82
+
83
+ </script>
package/math_minus.js ADDED
@@ -0,0 +1,54 @@
1
+ module.exports = function(RED) {
2
+
3
+ function MinusNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
6
+ var node = this;
7
+ this.property = config.property ?? "payload";
8
+ this.showState = config.showState;
9
+ this.filter = Boolean( config.filter );
10
+ this.last = null;
11
+
12
+ node.on('input', function(msg,send,done) {
13
+ if( msg.invalid )
14
+ {
15
+ done();
16
+ return null;
17
+ }
18
+ msg.payload = - Number( RED.util.getMessageProperty( msg, node.property ) );
19
+ let status = { text:msg.payload };
20
+ if( ! isNaN( msg.payload ) )
21
+ {
22
+ if( node.filter )
23
+ {
24
+ status.shape = "dot";
25
+ if( msg.payload !== node.last )
26
+ {
27
+ node.last = msg.payload;
28
+ status.fill = "green";
29
+ send( msg );
30
+ }
31
+ else
32
+ {
33
+ status.fill = "gray";
34
+ }
35
+ }
36
+ else
37
+ {
38
+ send( msg );
39
+ }
40
+ }
41
+ else
42
+ {
43
+ status.text = "not a Number";
44
+ }
45
+ if( node.showState )
46
+ {
47
+ node.status( status );
48
+ }
49
+ done();
50
+ });
51
+ }
52
+
53
+ RED.nodes.registerType("negate",MinusNode);
54
+ }
package/math_number.html CHANGED
@@ -5,7 +5,8 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
- showState:{value:false}
8
+ showState:{value:false},
9
+ filter:{value:false}
9
10
  },
10
11
  inputs:1,
11
12
  outputs:1,
@@ -43,6 +44,10 @@
43
44
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
44
45
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
45
46
  </div>
47
+ <div class="form-row">
48
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
49
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
50
+ </div>
46
51
  </script>
47
52
 
48
53
  <script type="text/html" data-help-name="tonumber">
package/math_number.js CHANGED
@@ -4,8 +4,10 @@ module.exports = function(RED) {
4
4
  RED.nodes.createNode(this,config);
5
5
  //this.config = config;
6
6
  var node = this;
7
- this.property = config.property ?? "payload";
7
+ this.property = config.property ?? "payload";
8
8
  this.showState = config.showState;
9
+ this.filter = Boolean( config.filter );
10
+ this.last = null;
9
11
 
10
12
  node.on('input', function(msg,send,done) {
11
13
  if( msg.invalid )
@@ -14,20 +16,35 @@ module.exports = function(RED) {
14
16
  return null;
15
17
  }
16
18
  msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
19
+ let status = { text:msg.payload };
17
20
  if( ! isNaN( msg.payload ) )
18
21
  {
19
- if( node.showState )
22
+ if( node.filter )
20
23
  {
21
- node.status( msg.payload );
24
+ status.shape = "dot";
25
+ if( msg.payload !== node.last )
26
+ {
27
+ node.last = msg.payload;
28
+ status.fill = "green";
29
+ send( msg );
30
+ }
31
+ else
32
+ {
33
+ status.fill = "gray";
34
+ }
35
+ }
36
+ else
37
+ {
38
+ send( msg );
22
39
  }
23
- send( msg );
24
40
  }
25
41
  else
26
42
  {
27
- if( node.showState )
28
- {
29
- node.status( "not a Number" );
30
- }
43
+ status.text = "not a Number";
44
+ }
45
+ if( node.showState )
46
+ {
47
+ node.status( status );
31
48
  }
32
49
  done();
33
50
  });
package/math_reduce.html CHANGED
@@ -16,7 +16,8 @@
16
16
  minData:{value:"1", required:true, validate:function(v){
17
17
  return v!=='' && !isNaN(v) && Number(v)>0;}
18
18
  },
19
- algo:{value:"", required:true}
19
+ algo:{value:"", required:true},
20
+ filter:{value:false}
20
21
  },
21
22
  inputs:1,
22
23
  outputs:1,
@@ -85,6 +86,10 @@
85
86
  <option value="max">Maximum</option>
86
87
  </select>
87
88
  </div>
89
+ <div class="form-row">
90
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
91
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
92
+ </div>
88
93
  </script>
89
94
 
90
95
  <script type="text/html" data-help-name="reduce">
package/math_reduce.js CHANGED
@@ -11,6 +11,8 @@ module.exports = function(RED) {
11
11
  this.maxMean = Number( config.maxMean );
12
12
  this.minData = Number( config.minData );
13
13
  this.algo = config.algo;
14
+ this.filter = Boolean( config.filter );
15
+ this.last = null;
14
16
 
15
17
  node.on('input', function(msg,send,done) {
16
18
  if( msg.invalid )
@@ -26,6 +28,7 @@ module.exports = function(RED) {
26
28
  else
27
29
  {
28
30
  const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
31
+ let status = { shape:"dot" };
29
32
  if( ! isNaN( payload ) )
30
33
  {
31
34
  let data = context.get( "data" ) ?? {};
@@ -73,18 +76,38 @@ module.exports = function(RED) {
73
76
  {
74
77
  case "mean": msg.payload /= msg.count; break;
75
78
  }
76
- node.status({fill:"green",shape:"dot",text:msg.payload});
77
- send( msg );
79
+ status.text = msg.payload;
80
+ if( node.filter )
81
+ {
82
+ if( msg.payload !== node.last )
83
+ {
84
+ node.last = msg.payload;
85
+ status.fill = "green";
86
+ send( msg );
87
+ }
88
+ else
89
+ {
90
+ status.fill = "gray";
91
+ }
92
+ }
93
+ else
94
+ {
95
+ status.fill = "green";
96
+ send( msg );
97
+ }
78
98
  }
79
99
  else
80
100
  {
81
- node.status({fill:"gray",shape:"dot",text:"to less data"});
101
+ status.fill = "gray";
102
+ status.text = "to less data";
82
103
  }
83
104
  }
84
105
  else
85
106
  {
86
- node.status({fill:"red",shape:"dot",text:"payload is NaN"});
107
+ status.fill = "red";
108
+ status.text = "payload is NaN";
87
109
  }
110
+ node.status( status );
88
111
  }
89
112
  done();
90
113
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "0.7.2",
3
+ "version": "0.9.0",
4
4
  "description": "nodes for simple operations.",
5
5
  "license": "LGPL-2.1",
6
6
  "homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",
@@ -19,9 +19,11 @@
19
19
  "nodes": {
20
20
  "counter":"counter.js",
21
21
  "tobool":"logic_bool.js",
22
+ "not":"logic_not.js",
22
23
  "or":"logic_or.js",
23
24
  "and":"logic_and.js",
24
25
  "tonumber":"math_number.js",
26
+ "negate":"math_minus.js",
25
27
  "reduce":"math_reduce.js",
26
28
  "fallingEdge":"math_falling.js",
27
29
  "raisingEdge":"math_raising.js",