@mschaeffler/node-red-hourmeter 0.1.1 → 0.2.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/hourmeter.html CHANGED
@@ -4,7 +4,8 @@
4
4
  color: "#dac4b4",
5
5
  defaults: {
6
6
  name: {value:""},
7
- topic:{value:""}
7
+ topic:{value:""},
8
+ cycle:{value:"0", required:true, validate:RED.validators.number()}
8
9
  },
9
10
  inputs:1,
10
11
  outputs:2,
@@ -27,6 +28,10 @@
27
28
  <label for="node-input-topic"><i class="fa fa-envelope-o"></i> Topic</label>
28
29
  <input type="text" id="node-input-topic" placeholder="Topic">
29
30
  </div>
31
+ <div class="form-row">
32
+ <label for="node-input-cycle"><i class="fa fa-hourglass-o"></i> Cycle [min]</label>
33
+ <input type="text" id="node-input-cycle">
34
+ </div>
30
35
  </script>
31
36
 
32
37
  <script type="text/html" data-help-name="hourmeter">
package/hourmeter.js CHANGED
@@ -1,12 +1,26 @@
1
- module.exports = function(RED) {
1
+ module.exports = function(RED)
2
+ {
2
3
 
3
- function HourMeterNode(config) {
4
+ function HourMeterNode(config)
5
+ {
4
6
  RED.nodes.createNode(this,config);
5
7
  this.config = config;
6
8
  this.topic = config.topic;
7
- var node = this;
9
+ this.cycle = config.cycle;
10
+ this.interval_id = null;
11
+ var node = this;
8
12
  var context = this.context();
9
- node.on('input', function(msg,send,done) {
13
+
14
+ if( this.cycle > 0 )
15
+ {
16
+ this.interval_id = setInterval( function()
17
+ {
18
+ node.emit( "input", {querry:true} );
19
+ }, this.cycle*60*1000 );
20
+ }
21
+
22
+ node.on( 'input', function(msg,send,done)
23
+ {
10
24
  if( msg.reset )
11
25
  {
12
26
  context.set( "data", undefined, "storeInFile" );
@@ -62,8 +76,16 @@ module.exports = function(RED) {
62
76
  send( [ { topic:this.topic, payload:data.switchOn!==undefined }, { topic:this.topic, payload:out } ] );
63
77
  }
64
78
  done();
65
- });
79
+ } );
66
80
  }
67
81
 
68
82
  RED.nodes.registerType("hourmeter",HourMeterNode);
83
+
84
+ HourMeterNode.prototype.close = function()
85
+ {
86
+ if( this.interval_id != null )
87
+ {
88
+ clearInterval( this.interval_id );
89
+ }
90
+ }
69
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-hourmeter",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "A working hour meter for NodeRed.",
5
5
  "license": "LGPL-2.1",
6
6
  "homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-hourmeter",