@mschaeffler/node-red-logic 1.4.2 → 1.4.4

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.js CHANGED
@@ -63,7 +63,7 @@ module.exports = function(RED) {
63
63
  {
64
64
  let data = context.get( "data" ) ?? {};
65
65
  const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
66
- if( msg.payload < this.threshold && this.threshold <= last )
66
+ if( msg.payload < node.threshold && node.threshold <= last )
67
67
  {
68
68
  status.fill = "green";
69
69
  msg.edge = "falling";
@@ -76,11 +76,11 @@ module.exports = function(RED) {
76
76
 
77
77
  if( last )
78
78
  {
79
- if( msg.payload > this.threshold_raise && this.threshold_raise >= last.value && last.edge != 'rising')
79
+ if( msg.payload > node.threshold_raise && node.threshold_raise >= last.value && last.edge != 'rising')
80
80
  {
81
81
  sendMsg( 'rising' );
82
82
  }
83
- else if( msg.payload < this.threshold_fall && this.threshold_fall <= last.value && last.edge != 'falling')
83
+ else if( msg.payload < node.threshold_fall && node.threshold_fall <= last.value && last.edge != 'falling')
84
84
  {
85
85
  sendMsg( 'falling' );
86
86
  }
@@ -88,11 +88,11 @@ module.exports = function(RED) {
88
88
  else
89
89
  {
90
90
  data[msg.topic] = {};
91
- if( ['any','rising'].includes(this.initial) && msg.payload > this.threshold_raise )
91
+ if( ['any','rising'].includes(node.initial) && msg.payload > node.threshold_raise )
92
92
  {
93
93
  sendMsg( 'rising' );
94
94
  }
95
- else if( ['any','falling'].includes(this.initial) && msg.payload < this.threshold_fall )
95
+ else if( ['any','falling'].includes(node.initial) && msg.payload < node.threshold_fall )
96
96
  {
97
97
  sendMsg( 'falling' );
98
98
  }
package/math_mean.js CHANGED
@@ -83,18 +83,18 @@ module.exports = function(RED) {
83
83
  send( msg );
84
84
  }
85
85
 
86
- if( this.zeroIsZero && payload === 0 )
86
+ if( node.zeroIsZero && payload === 0 )
87
87
  {
88
88
  sendValue( 0 );
89
89
  }
90
- else if( item.length >= this.minData )
90
+ else if( item.length >= node.minData )
91
91
  {
92
92
  let sum = 0;
93
93
  for( const value of item )
94
94
  {
95
95
  sum += value.value;
96
96
  }
97
- if( (last[msg.topic]??0)+this.filter < now )
97
+ if( (last[msg.topic]??0)+node.filter < now )
98
98
  {
99
99
  sendValue( sum/item.length );
100
100
  }
package/math_minus.js CHANGED
@@ -6,7 +6,7 @@ module.exports = function(RED) {
6
6
  var node = this;
7
7
  this.property = config.property ?? "payload";
8
8
  this.propertyType = config.propertyType ?? "msg";
9
- this.showState = config.showState;
9
+ this.showState = Boolean( config.showState );
10
10
  this.filter = Boolean( config.filter );
11
11
  this.last = null;
12
12
  if( this.propertyType === "jsonata" )
@@ -49,7 +49,7 @@ module.exports = function(RED) {
49
49
  }
50
50
  getPayload( function(value)
51
51
  {
52
- msg.payload = Number( value );
52
+ msg.payload = - Number( value );
53
53
  let status = { text:msg.payload };
54
54
  if( ! isNaN( msg.payload ) )
55
55
  {
package/math_number.js CHANGED
@@ -6,7 +6,7 @@ module.exports = function(RED) {
6
6
  var node = this;
7
7
  this.property = config.property ?? "payload";
8
8
  this.propertyType = config.propertyType ?? "msg";
9
- this.showState = config.showState;
9
+ this.showState = Boolean( config.showState );
10
10
  this.filter = Boolean( config.filter );
11
11
  this.last = null;
12
12
  if( this.propertyType === "jsonata" )
package/math_raising.js CHANGED
@@ -33,6 +33,7 @@ module.exports = function(RED) {
33
33
  }
34
34
  else
35
35
  {
36
+ node.done = done;
36
37
  function getPayload(callback)
37
38
  {
38
39
  if( node.propertyPrepared )
@@ -63,7 +64,7 @@ module.exports = function(RED) {
63
64
  {
64
65
  let data = context.get( "data" ) ?? {};
65
66
  const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
66
- if( msg.payload > this.threshold && this.threshold >= last )
67
+ if( msg.payload > node.threshold && node.threshold >= last )
67
68
  {
68
69
  status.fill = "green";
69
70
  msg.edge = "raising";
@@ -63,14 +63,14 @@ module.exports = function(RED) {
63
63
  let data = context.get( "data" ) ?? {};
64
64
  let item = data[msg.topic] ?? [];
65
65
  item.push( { time:now, value:payload } );
66
- while( item[0].time < now - this.deltaTime )
66
+ while( item[0].time < now - node.deltaTime )
67
67
  {
68
68
  item.shift();
69
69
  }
70
70
  data[msg.topic] = item;
71
71
  context.set( "data", data );
72
72
 
73
- if( item.length >= this.minData )
73
+ if( item.length >= node.minData )
74
74
  {
75
75
  msg.stat = {
76
76
  count: item.length,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
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",
@@ -17,19 +17,19 @@
17
17
  "node-red": {
18
18
  "version": ">=3.1.0",
19
19
  "nodes": {
20
- "counter":"counter.js",
21
- "tobool":"logic_bool.js",
22
- "not":"logic_not.js",
23
- "or":"logic_or.js",
24
- "and":"logic_and.js",
25
- "tonumber":"math_number.js",
26
- "negate":"math_minus.js",
27
- "reduce":"math_reduce.js",
28
- "fallingEdge":"math_falling.js",
29
- "raisingEdge":"math_raising.js",
30
- "hysteresisEdge":"math_hysteresis.js",
31
- "statistics":"math_statistics.js",
32
- "mean":"math_mean.js"
20
+ "counter": "counter.js",
21
+ "tobool": "logic_bool.js",
22
+ "not": "logic_not.js",
23
+ "or": "logic_or.js",
24
+ "and": "logic_and.js",
25
+ "tonumber": "math_number.js",
26
+ "negate": "math_minus.js",
27
+ "reduce": "math_reduce.js",
28
+ "fallingEdge": "math_falling.js",
29
+ "raisingEdge": "math_raising.js",
30
+ "hysteresisEdge": "math_hysteresis.js",
31
+ "statistics": "math_statistics.js",
32
+ "mean": "math_mean.js"
33
33
  }
34
34
  },
35
35
  "author": {
package/tools.js CHANGED
@@ -21,3 +21,39 @@ exports.property2boolean = function(input)
21
21
  return null;
22
22
  }
23
23
  }
24
+
25
+ exports.prepareProperty = function(node)
26
+ {
27
+ if( node.propertyType === "jsonata" )
28
+ {
29
+ try {
30
+ node.propertyPrepared = RED.util.prepareJSONataExpression( node.property, node );
31
+ }
32
+ catch (e) {
33
+ node.error( RED._( "debug.invalid-exp", {error:node.property} ) );
34
+ return;
35
+ }
36
+ }
37
+ }
38
+
39
+ exports.getPayload = function(node,msg,callback)
40
+ {
41
+ if( node.propertyPrepared )
42
+ {
43
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
44
+ {
45
+ if( err )
46
+ {
47
+ node.done( RED._( "debug.invalid-exp", {error:node.property} ) );
48
+ }
49
+ else
50
+ {
51
+ callback( value );
52
+ }
53
+ } );
54
+ }
55
+ else
56
+ {
57
+ callback( RED.util.getMessageProperty( msg, node.property ) );
58
+ }
59
+ }