@mschaeffler/node-red-logic 1.3.0 → 1.4.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/math_falling.html CHANGED
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
+ propertyType:{value:"msg"},
8
9
  threshold:{value:"",required:true,validate:RED.validators.number()},
9
10
  showState:{value:false}
10
11
  },
@@ -23,8 +24,8 @@
23
24
  oneditprepare: function() {
24
25
  $("#node-input-property").typedInput({
25
26
  type:"msg",
26
- types:["msg"],
27
- typeField: "#node-input-property-type"
27
+ types:["msg","jsonata"],
28
+ typeField: "#node-input-propertyType"
28
29
  })
29
30
  }
30
31
  });
@@ -38,7 +39,7 @@
38
39
  <div class="form-row">
39
40
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
41
  <input type="text" id="node-input-property">
41
- <input type="hidden" id="node-input-property-type">
42
+ <input type="hidden" id="node-input-propertyType">
42
43
  </div>
43
44
  <div class="form-row">
44
45
  <label for="node-input-threshold"><i class="fa fa-chevron-down"></i> Threshold</label>
package/math_falling.js CHANGED
@@ -3,11 +3,22 @@ module.exports = function(RED) {
3
3
  function FallingEdgeNode(config) {
4
4
  RED.nodes.createNode(this,config);
5
5
  //this.config = config;
6
- var node = this;
6
+ var node = this;
7
7
  var context = this.context();
8
- this.property = config.property ?? "payload";
9
- this.threshold = config.threshold;
10
- this.showState = config.showState;
8
+ this.property = config.property ?? "payload";
9
+ this.propertyType = config.propertyType ?? "msg";
10
+ this.threshold = config.threshold;
11
+ this.showState = config.showState;
12
+ if( this.propertyType === "jsonata" )
13
+ {
14
+ try {
15
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
16
+ }
17
+ catch (e) {
18
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
19
+ return;
20
+ }
21
+ }
11
22
 
12
23
  node.on('input', function(msg,send,done) {
13
24
  if( msg.invalid )
@@ -19,37 +30,62 @@ module.exports = function(RED) {
19
30
  {
20
31
  context.set( "data", {} );
21
32
  node.status( "" );
33
+ done();
22
34
  }
23
35
  else
24
36
  {
25
- msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
26
- let status = { fill:"gray", shape:"dot", text:msg.payload };
27
-
28
- if( ! isNaN( msg.payload ) )
37
+ function getPayload(callback)
29
38
  {
30
- let data = context.get( "data" ) ?? {};
31
- const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
32
- if( msg.payload < this.threshold && this.threshold <= last )
39
+ if( node.propertyPrepared )
33
40
  {
34
- status.fill = "green";
35
- msg.edge = "falling";
36
- send( msg );
41
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
42
+ {
43
+ if( err )
44
+ {
45
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
46
+ }
47
+ else
48
+ {
49
+ callback( value );
50
+ }
51
+ } );
52
+ }
53
+ else
54
+ {
55
+ callback( RED.util.getMessageProperty( msg, node.property ) );
37
56
  }
38
- data[msg.topic] = msg.payload;
39
- context.set( "data", data );
40
57
  }
41
- else
58
+ getPayload( function(value)
42
59
  {
43
- status.fill = "red";
44
- status.text = "not a Number";
45
- }
60
+ msg.payload = Number( value );
61
+ let status = { fill:"gray", shape:"dot", text:msg.payload };
46
62
 
47
- if( node.showState )
48
- {
49
- node.status( status );
50
- }
63
+ if( ! isNaN( msg.payload ) )
64
+ {
65
+ let data = context.get( "data" ) ?? {};
66
+ const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
67
+ if( msg.payload < this.threshold && this.threshold <= last )
68
+ {
69
+ status.fill = "green";
70
+ msg.edge = "falling";
71
+ send( msg );
72
+ }
73
+ data[msg.topic] = msg.payload;
74
+ context.set( "data", data );
75
+ }
76
+ else
77
+ {
78
+ status.fill = "red";
79
+ status.text = "not a Number";
80
+ }
81
+
82
+ if( node.showState )
83
+ {
84
+ node.status( status );
85
+ }
86
+ done();
87
+ } );
51
88
  }
52
- done();
53
89
  });
54
90
  }
55
91
 
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
+ propertyType:{value:"msg"},
8
9
  threshold_raise:{value:"",required:true,validate:RED.validators.number()},
9
10
  threshold_fall:{value:"",required:true,validate:function(v){
10
11
  const raise = $("#node-input-threshold_raise").length ? $("#node-input-threshold_raise").val() : this.threshold_raise;
@@ -28,8 +29,8 @@
28
29
  oneditprepare: function() {
29
30
  $("#node-input-property").typedInput({
30
31
  type:"msg",
31
- types:["msg"],
32
- typeField: "#node-input-property-type"
32
+ types:["msg","jsonata"],
33
+ typeField: "#node-input-propertyType"
33
34
  })
34
35
  }
35
36
  });
@@ -43,7 +44,7 @@
43
44
  <div class="form-row">
44
45
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
45
46
  <input type="text" id="node-input-property">
46
- <input type="hidden" id="node-input-property-type">
47
+ <input type="hidden" id="node-input-propertyType">
47
48
  </div>
48
49
  <div class="form-row">
49
50
  <label for="node-input-threshold_raise"><i class="fa fa-chevron-up"></i> up threshold</label>
@@ -3,13 +3,24 @@ module.exports = function(RED) {
3
3
  function HysteresisEdgeNode(config) {
4
4
  RED.nodes.createNode(this,config);
5
5
  //this.config = config;
6
- var node = this;
6
+ var node = this;
7
7
  var context = this.context();
8
8
  this.property = config.property ?? "payload";
9
+ this.propertyType = config.propertyType ?? "msg";
9
10
  this.threshold_raise = config.threshold_raise;
10
11
  this.threshold_fall = config.threshold_fall;
11
12
  this.initial = config.initial;
12
13
  this.showState = config.showState;
14
+ if( this.propertyType === "jsonata" )
15
+ {
16
+ try {
17
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
18
+ }
19
+ catch (e) {
20
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
21
+ return;
22
+ }
23
+ }
13
24
 
14
25
  node.on('input', function(msg,send,done) {
15
26
  if( msg.invalid )
@@ -21,63 +32,88 @@ module.exports = function(RED) {
21
32
  {
22
33
  context.set( "data", {} );
23
34
  node.status( "" );
35
+ done();
24
36
  }
25
37
  else
26
38
  {
27
- msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
28
- let status = { fill:"gray", shape:"dot", text:msg.payload };
29
-
30
- if( ! isNaN( msg.payload ) )
39
+ function getPayload(callback)
31
40
  {
32
- let data = context.get( "data" ) ?? {};
33
- const last = data[msg.topic];
34
-
35
- function sendMsg(edge)
41
+ if( node.propertyPrepared )
36
42
  {
37
- status.fill = "green";
38
- data[msg.topic].edge = edge;
39
- msg.edge = edge;
40
- send( msg );
43
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
44
+ {
45
+ if( err )
46
+ {
47
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
48
+ }
49
+ else
50
+ {
51
+ callback( value );
52
+ }
53
+ } );
41
54
  }
55
+ else
56
+ {
57
+ callback( RED.util.getMessageProperty( msg, node.property ) );
58
+ }
59
+ }
60
+ getPayload( function(value)
61
+ {
62
+ msg.payload = Number( value );
63
+ let status = { fill:"gray", shape:"dot", text:msg.payload };
42
64
 
43
- if( last )
65
+ if( ! isNaN( msg.payload ) )
44
66
  {
45
- if( msg.payload > this.threshold_raise && this.threshold_raise >= last.value && last.edge != 'rising')
67
+ let data = context.get( "data" ) ?? {};
68
+ const last = data[msg.topic];
69
+
70
+ function sendMsg(edge)
71
+ {
72
+ status.fill = "green";
73
+ data[msg.topic].edge = edge;
74
+ msg.edge = edge;
75
+ send( msg );
76
+ }
77
+
78
+ if( last )
46
79
  {
47
- sendMsg( 'rising' );
80
+ if( msg.payload > this.threshold_raise && this.threshold_raise >= last.value && last.edge != 'rising')
81
+ {
82
+ sendMsg( 'rising' );
83
+ }
84
+ else if( msg.payload < this.threshold_fall && this.threshold_fall <= last.value && last.edge != 'falling')
85
+ {
86
+ sendMsg( 'falling' );
87
+ }
48
88
  }
49
- else if( msg.payload < this.threshold_fall && this.threshold_fall <= last.value && last.edge != 'falling')
89
+ else
50
90
  {
51
- sendMsg( 'falling' );
91
+ data[msg.topic] = {};
92
+ if( ['any','rising'].includes(this.initial) && msg.payload > this.threshold_raise )
93
+ {
94
+ sendMsg( 'rising' );
95
+ }
96
+ else if( ['any','falling'].includes(this.initial) && msg.payload < this.threshold_fall )
97
+ {
98
+ sendMsg( 'falling' );
99
+ }
52
100
  }
101
+ data[msg.topic].value = msg.payload;
102
+ context.set( "data", data );
53
103
  }
54
104
  else
55
105
  {
56
- data[msg.topic] = {};
57
- if( ['any','rising'].includes(this.initial) && msg.payload > this.threshold_raise )
58
- {
59
- sendMsg( 'rising' );
60
- }
61
- else if( ['any','falling'].includes(this.initial) && msg.payload < this.threshold_fall )
62
- {
63
- sendMsg( 'falling' );
64
- }
106
+ status.fill = "red";
107
+ status.text = "not a Number";
65
108
  }
66
- data[msg.topic].value = msg.payload;
67
- context.set( "data", data );
68
- }
69
- else
70
- {
71
- status.fill = "red";
72
- status.text = "not a Number";
73
- }
74
109
 
75
- if( node.showState )
76
- {
77
- node.status( status );
78
- }
110
+ if( node.showState )
111
+ {
112
+ node.status( status );
113
+ }
114
+ done();
115
+ } );
79
116
  }
80
- done();
81
117
  });
82
118
  }
83
119
 
package/math_raising.html CHANGED
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
+ propertyType:{value:"msg"},
8
9
  threshold:{value:"",required:true,validate:RED.validators.number()},
9
10
  showState:{value:false}
10
11
  },
@@ -23,8 +24,8 @@
23
24
  oneditprepare: function() {
24
25
  $("#node-input-property").typedInput({
25
26
  type:"msg",
26
- types:["msg"],
27
- typeField: "#node-input-property-type"
27
+ types:["msg","jsonata"],
28
+ typeField: "#node-input-propertyType"
28
29
  })
29
30
  }
30
31
  });
@@ -38,7 +39,7 @@
38
39
  <div class="form-row">
39
40
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
41
  <input type="text" id="node-input-property">
41
- <input type="hidden" id="node-input-property-type">
42
+ <input type="hidden" id="node-input-propertyType">
42
43
  </div>
43
44
  <div class="form-row">
44
45
  <label for="node-input-threshold"><i class="fa fa-chevron-up"></i> Threshold</label>
package/math_raising.js CHANGED
@@ -3,11 +3,22 @@ module.exports = function(RED) {
3
3
  function RaisingEdgeNode(config) {
4
4
  RED.nodes.createNode(this,config);
5
5
  //this.config = config;
6
- var node = this;
6
+ var node = this;
7
7
  var context = this.context();
8
- this.property = config.property ?? "payload";
9
- this.threshold = config.threshold;
10
- this.showState = config.showState;
8
+ this.property = config.property ?? "payload";
9
+ this.propertyType = config.propertyType ?? "msg";
10
+ this.threshold = config.threshold;
11
+ this.showState = config.showState;
12
+ if( this.propertyType === "jsonata" )
13
+ {
14
+ try {
15
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
16
+ }
17
+ catch (e) {
18
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
19
+ return;
20
+ }
21
+ }
11
22
 
12
23
  node.on('input', function(msg,send,done) {
13
24
  if( msg.invalid )
@@ -19,37 +30,62 @@ module.exports = function(RED) {
19
30
  {
20
31
  context.set( "data", {} );
21
32
  node.status( "" );
33
+ done();
22
34
  }
23
35
  else
24
36
  {
25
- msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
26
- let status = { fill:"gray", shape:"dot", text:msg.payload };
27
-
28
- if( ! isNaN( msg.payload ) )
37
+ function getPayload(callback)
29
38
  {
30
- let data = context.get( "data" ) ?? {};
31
- const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
32
- if( msg.payload > this.threshold && this.threshold >= last )
39
+ if( node.propertyPrepared )
33
40
  {
34
- status.fill = "green";
35
- msg.edge = "raising";
36
- send( msg );
41
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
42
+ {
43
+ if( err )
44
+ {
45
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
46
+ }
47
+ else
48
+ {
49
+ callback( value );
50
+ }
51
+ } );
52
+ }
53
+ else
54
+ {
55
+ callback( RED.util.getMessageProperty( msg, node.property ) );
37
56
  }
38
- data[msg.topic] = msg.payload;
39
- context.set( "data", data );
40
57
  }
41
- else
58
+ getPayload( function(value)
42
59
  {
43
- status.fill = "red";
44
- status.text = "not a Number";
45
- }
60
+ msg.payload = Number( value );
61
+ let status = { fill:"gray", shape:"dot", text:msg.payload };
46
62
 
47
- if( node.showState )
48
- {
49
- node.status( status );
50
- }
63
+ if( ! isNaN( msg.payload ) )
64
+ {
65
+ let data = context.get( "data" ) ?? {};
66
+ const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
67
+ if( msg.payload > this.threshold && this.threshold >= last )
68
+ {
69
+ status.fill = "green";
70
+ msg.edge = "raising";
71
+ send( msg );
72
+ }
73
+ data[msg.topic] = msg.payload;
74
+ context.set( "data", data );
75
+ }
76
+ else
77
+ {
78
+ status.fill = "red";
79
+ status.text = "not a Number";
80
+ }
81
+
82
+ if( node.showState )
83
+ {
84
+ node.status( status );
85
+ }
86
+ done();
87
+ } );
51
88
  }
52
- done();
53
89
  });
54
90
  }
55
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "1.3.0",
3
+ "version": "1.4.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",
@@ -9,13 +9,13 @@
9
9
  "url": "git+https://github.com/m-schaeffler/node-red-my-nodes.git"
10
10
  },
11
11
  "engines": {
12
- "node": ">=16"
12
+ "node": ">=18"
13
13
  },
14
14
  "keywords": [
15
15
  "node-red"
16
16
  ],
17
17
  "node-red": {
18
- "version": ">=3.0.0",
18
+ "version": ">=3.1.0",
19
19
  "nodes": {
20
20
  "counter":"counter.js",
21
21
  "tobool":"logic_bool.js",