@mschaeffler/node-red-hourmeter 0.3.0 → 1.0.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/README.md +1 -0
- package/examples/hourmeter.json +56 -32
- package/examples/hourmeter.png +0 -0
- package/hourmeter.html +2 -0
- package/hourmeter.js +35 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ A [local filesystem context store](https://nodered.org/docs/user-guide/context#s
|
|
|
37
37
|
|:-------|:-------|:----------------------------------|
|
|
38
38
|
|payload | | Starts or stopps the counting. |
|
|
39
39
|
|reset |boolean |If true, resets the counter to 0.|
|
|
40
|
+
|set |boolean |If true, sets the counter to `payload`.|
|
|
40
41
|
|query |boolean |If true, just querries the state of the counter.|
|
|
41
42
|
|
|
42
43
|
### Outputs
|
package/examples/hourmeter.json
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
[
|
|
2
|
-
{
|
|
3
|
-
"id": "5535ca07b24e93fb",
|
|
4
|
-
"type": "tab",
|
|
5
|
-
"label": "Flow 1",
|
|
6
|
-
"disabled": false,
|
|
7
|
-
"info": "",
|
|
8
|
-
"env": []
|
|
9
|
-
},
|
|
10
2
|
{
|
|
11
3
|
"id": "3412a0829ce8c730",
|
|
12
4
|
"type": "inject",
|
|
@@ -25,11 +17,11 @@
|
|
|
25
17
|
"crontab": "",
|
|
26
18
|
"once": false,
|
|
27
19
|
"onceDelay": 0.1,
|
|
28
|
-
"topic": "",
|
|
29
|
-
"payload": "
|
|
30
|
-
"payloadType": "
|
|
31
|
-
"x":
|
|
32
|
-
"y":
|
|
20
|
+
"topic": "FooBar",
|
|
21
|
+
"payload": "true",
|
|
22
|
+
"payloadType": "bool",
|
|
23
|
+
"x": 470,
|
|
24
|
+
"y": 320,
|
|
33
25
|
"wires": [
|
|
34
26
|
[
|
|
35
27
|
"fd93870645a4a85f"
|
|
@@ -54,11 +46,11 @@
|
|
|
54
46
|
"crontab": "",
|
|
55
47
|
"once": false,
|
|
56
48
|
"onceDelay": 0.1,
|
|
57
|
-
"topic": "",
|
|
58
|
-
"payload": "
|
|
59
|
-
"payloadType": "
|
|
60
|
-
"x":
|
|
61
|
-
"y":
|
|
49
|
+
"topic": "FooBar",
|
|
50
|
+
"payload": "false",
|
|
51
|
+
"payloadType": "bool",
|
|
52
|
+
"x": 470,
|
|
53
|
+
"y": 360,
|
|
62
54
|
"wires": [
|
|
63
55
|
[
|
|
64
56
|
"fd93870645a4a85f"
|
|
@@ -70,7 +62,7 @@
|
|
|
70
62
|
"type": "debug",
|
|
71
63
|
"z": "5535ca07b24e93fb",
|
|
72
64
|
"name": "debug 8",
|
|
73
|
-
"active":
|
|
65
|
+
"active": true,
|
|
74
66
|
"tosidebar": true,
|
|
75
67
|
"console": false,
|
|
76
68
|
"tostatus": true,
|
|
@@ -92,10 +84,6 @@
|
|
|
92
84
|
"p": "reset",
|
|
93
85
|
"v": "true",
|
|
94
86
|
"vt": "bool"
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"p": "topic",
|
|
98
|
-
"vt": "str"
|
|
99
87
|
}
|
|
100
88
|
],
|
|
101
89
|
"repeat": "",
|
|
@@ -103,8 +91,8 @@
|
|
|
103
91
|
"once": false,
|
|
104
92
|
"onceDelay": 0.1,
|
|
105
93
|
"topic": "",
|
|
106
|
-
"x":
|
|
107
|
-
"y":
|
|
94
|
+
"x": 470,
|
|
95
|
+
"y": 200,
|
|
108
96
|
"wires": [
|
|
109
97
|
[
|
|
110
98
|
"fd93870645a4a85f"
|
|
@@ -121,10 +109,6 @@
|
|
|
121
109
|
"p": "querry",
|
|
122
110
|
"v": "true",
|
|
123
111
|
"vt": "bool"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
"p": "topic",
|
|
127
|
-
"vt": "str"
|
|
128
112
|
}
|
|
129
113
|
],
|
|
130
114
|
"repeat": "",
|
|
@@ -132,8 +116,8 @@
|
|
|
132
116
|
"once": false,
|
|
133
117
|
"onceDelay": 0.1,
|
|
134
118
|
"topic": "",
|
|
135
|
-
"x":
|
|
136
|
-
"y":
|
|
119
|
+
"x": 470,
|
|
120
|
+
"y": 260,
|
|
137
121
|
"wires": [
|
|
138
122
|
[
|
|
139
123
|
"fd93870645a4a85f"
|
|
@@ -147,6 +131,8 @@
|
|
|
147
131
|
"name": "",
|
|
148
132
|
"topic": "test",
|
|
149
133
|
"cycle": "15",
|
|
134
|
+
"contextStore": "memoryOnly",
|
|
135
|
+
"showState": true,
|
|
150
136
|
"x": 650,
|
|
151
137
|
"y": 260,
|
|
152
138
|
"wires": [
|
|
@@ -163,7 +149,7 @@
|
|
|
163
149
|
"type": "debug",
|
|
164
150
|
"z": "5535ca07b24e93fb",
|
|
165
151
|
"name": "debug 9",
|
|
166
|
-
"active":
|
|
152
|
+
"active": true,
|
|
167
153
|
"tosidebar": true,
|
|
168
154
|
"console": false,
|
|
169
155
|
"tostatus": true,
|
|
@@ -174,5 +160,43 @@
|
|
|
174
160
|
"x": 840,
|
|
175
161
|
"y": 300,
|
|
176
162
|
"wires": []
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "a831f554dd6fce40",
|
|
166
|
+
"type": "inject",
|
|
167
|
+
"z": "5535ca07b24e93fb",
|
|
168
|
+
"name": "set",
|
|
169
|
+
"props": [
|
|
170
|
+
{
|
|
171
|
+
"p": "set",
|
|
172
|
+
"v": "true",
|
|
173
|
+
"vt": "bool"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"p": "payload"
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
"repeat": "",
|
|
180
|
+
"crontab": "",
|
|
181
|
+
"once": false,
|
|
182
|
+
"onceDelay": 0.1,
|
|
183
|
+
"topic": "",
|
|
184
|
+
"payload": "12",
|
|
185
|
+
"payloadType": "num",
|
|
186
|
+
"x": 470,
|
|
187
|
+
"y": 160,
|
|
188
|
+
"wires": [
|
|
189
|
+
[
|
|
190
|
+
"fd93870645a4a85f"
|
|
191
|
+
]
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"id": "55acd484dd996916",
|
|
196
|
+
"type": "global-config",
|
|
197
|
+
"env": [],
|
|
198
|
+
"modules": {
|
|
199
|
+
"@mschaeffler/node-red-hourmeter": "1.0.0"
|
|
200
|
+
}
|
|
177
201
|
}
|
|
178
202
|
]
|
package/examples/hourmeter.png
CHANGED
|
Binary file
|
package/hourmeter.html
CHANGED
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
<dd> Starts or stopps the counting.</dd>
|
|
91
91
|
<dt>reset <span class="property-type">boolean</span></dt>
|
|
92
92
|
<dd> If true, resets the counter to 0.</dd>
|
|
93
|
+
<dt>set <span class="property-type">boolean</span></dt>
|
|
94
|
+
<dd> If true, sets the counter to <code>payload</code>.</dd>
|
|
93
95
|
<dt>query <span class="property-type">boolean</span></dt>
|
|
94
96
|
<dd> If true, just querries the state of the counter.</dd>
|
|
95
97
|
</dl>
|
package/hourmeter.js
CHANGED
|
@@ -26,7 +26,8 @@ module.exports = function(RED)
|
|
|
26
26
|
|
|
27
27
|
node.on( 'input', function(msg,send,done)
|
|
28
28
|
{
|
|
29
|
-
let
|
|
29
|
+
let data;
|
|
30
|
+
const now = Date.now();
|
|
30
31
|
|
|
31
32
|
function sendOutput(reason)
|
|
32
33
|
{
|
|
@@ -49,13 +50,40 @@ module.exports = function(RED)
|
|
|
49
50
|
}
|
|
50
51
|
else
|
|
51
52
|
{
|
|
52
|
-
const now = Date.now();
|
|
53
53
|
data = context.get( "data", node.contextStore ) ?? { counter:0 };
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if( msg.set )
|
|
55
|
+
{
|
|
56
|
+
const value = Number( msg.payload );
|
|
57
|
+
if( value >= 0 )
|
|
58
|
+
{
|
|
59
|
+
data.counter = msg.payload * 3600;
|
|
60
|
+
if( data.switchOn !== undefined )
|
|
61
|
+
{
|
|
62
|
+
data.switchOn = now;
|
|
63
|
+
}
|
|
64
|
+
context.set( "data", data, node.contextStore );
|
|
65
|
+
sendOutput( "set" );
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
{
|
|
69
|
+
done( `invalid set value: ${msg.payload}` )
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else
|
|
56
74
|
{
|
|
57
|
-
if( msg.
|
|
75
|
+
if( msg.query )
|
|
58
76
|
{
|
|
77
|
+
if( data.switchOn !== undefined )
|
|
78
|
+
{
|
|
79
|
+
data.counter += (now - data.switchOn)/1000;
|
|
80
|
+
data.switchOn = now;
|
|
81
|
+
}
|
|
82
|
+
sendOutput( "query" );
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
{
|
|
86
|
+
data.state = msg.payload;
|
|
59
87
|
switch( msg.payload )
|
|
60
88
|
{
|
|
61
89
|
case true:
|
|
@@ -84,20 +112,12 @@ module.exports = function(RED)
|
|
|
84
112
|
sendOutput( "off" );
|
|
85
113
|
}
|
|
86
114
|
break;
|
|
115
|
+
default:
|
|
116
|
+
node.warn( `invalid payload: ${msg.payload}` );
|
|
87
117
|
}
|
|
88
|
-
data.state = msg.payload;
|
|
89
118
|
context.set( "data", data, node.contextStore );
|
|
90
119
|
}
|
|
91
120
|
}
|
|
92
|
-
else
|
|
93
|
-
{
|
|
94
|
-
if( data.switchOn !== undefined )
|
|
95
|
-
{
|
|
96
|
-
data.counter += (now - data.switchOn)/1000;
|
|
97
|
-
data.switchOn = now;
|
|
98
|
-
}
|
|
99
|
-
sendOutput( "query" );
|
|
100
|
-
}
|
|
101
121
|
}
|
|
102
122
|
done();
|
|
103
123
|
} );
|
package/package.json
CHANGED