node-red-contrib-boolean-logic-ultimate 1.0.48 → 1.0.49

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/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # node-red-contrib-boolean-logic-ultimate
2
2
  [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square)](https://www.paypal.me/techtoday)
3
3
 
4
+ <p>
5
+ <b>Version 1.0.48</b> February 2022<br/>
6
+ - NEW: TOGGLE node: Simple toggle node.</br>
7
+ </p>
4
8
  <p>
5
9
  <b>Version 1.0.48</b> February 2022<br/>
6
10
  - NEW: SUM node: this new node makes sum, average and measurement count.</br>
package/README.md CHANGED
@@ -358,6 +358,23 @@ resets the values to zero.
358
358
  }
359
359
  </pre>
360
360
 
361
+ br/>
362
+ <br/>
363
+ <br/>
364
+ <br/>
365
+ <br/>
366
+
367
+ # TOGGLE ULTIMATE
368
+
369
+ The pourpose of this node is to toggle between true/false the payload of every incoming message.<br />
370
+
371
+
372
+ **INPUT**<br />
373
+
374
+ Any message that arrives on input, will be passwd through to the output with the payload toggled between true and false.
375
+
376
+
377
+
361
378
  [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
362
379
  [license-url]: https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/LICENSE
363
380
  [npm-url]: https://npmjs.org/package/node-red-contrib-boolean-logic-ultimate
@@ -0,0 +1,63 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('toggleUltimate', {
3
+ category: 'boolean logic ultimate',
4
+ color: '#ff8080',
5
+ defaults: {
6
+ name: {
7
+ value: "Toggle"
8
+ },
9
+ valueToToggle: { value: "true" }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: "serial.png",
14
+ label:
15
+ function () {
16
+ return this.name || "Toggle";
17
+ },
18
+ paletteLabel: function () {
19
+ return "toggleUltimate";
20
+ }
21
+ });
22
+ </script>
23
+
24
+ <script type="text/x-red" data-template-name="toggleUltimate">
25
+ <div class="form-row">
26
+ <b>Toggle Ultimate</b>&nbsp&nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-question-circle"></i>&nbsp<a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate"><u>Help online</u></a></span>
27
+ <br/>
28
+ <br/>
29
+ </div>
30
+ <div class="form-row">
31
+ <label for="node-input-name"><i class="icon-tag"></i> Name</label>
32
+ <input type="text" id="node-input-name" placeholder="Name">
33
+ </div>
34
+ <div class="form-row">
35
+ <label style="width:160px" for="node-input-valueToToggle"><i class="fa fa-toggle-on"></i> Initial value</label>
36
+ <select type="text" id="node-input-valueToToggle" placeholder="">
37
+ <option value="true">Initialize wiht True</option>
38
+ <option value="false">Initialize with False</option>
39
+ </select>
40
+ </div>
41
+ <!-- <div class="form-row">
42
+ <input type="checkbox" id="node-input-homeAssitantBoolean" style="display:inline-block; width:auto; vertical-align:top;">
43
+ &nbsp;
44
+ <label style="width:85%" for="node-input-homeAssitantBoolean">
45
+ <i class="fa fa-home"></i>&nbsp;Output Home Assistant "on"/"off" instead of true/false
46
+ </label>
47
+ </div> -->
48
+
49
+
50
+ </script>
51
+
52
+ <script type="text/x-red" data-help-name="toggleUltimate">
53
+ <p>
54
+ SEE THE README FOR HELP CONFIGURING THE NODE
55
+ </p>
56
+
57
+ <p>
58
+ <a href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate" target="_blank">Click here to learn how to configure the node.</a>
59
+ </p>
60
+
61
+ <a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a>
62
+
63
+ </script>
@@ -0,0 +1,71 @@
1
+ module.exports = function (RED) {
2
+ function toggleUltimate(config) {
3
+ RED.nodes.createNode(this, config);
4
+ this.config = config;
5
+ var node = this;
6
+ node.valueToToggle = config.valueToToggle === undefined ? true : ToBoolean(config.valueToToggle);
7
+
8
+ function setNodeStatus({ fill, shape, text }) {
9
+ var dDate = new Date();
10
+ node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
11
+ }
12
+
13
+ setNodeStatus({ fill: "grey", shape: "dot", text: "Waiting" });
14
+
15
+ this.on('input', function (msg) {
16
+
17
+
18
+ // 15/11/2021 inform user about undefined topic or payload
19
+ if (!msg.hasOwnProperty("payload") || msg.payload === undefined || msg.payload === null) {
20
+ setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
21
+ return;
22
+ }
23
+
24
+ node.valueToToggle = !node.valueToToggle;
25
+
26
+ var msgOUT = RED.util.cloneMessage(msg);
27
+ try {
28
+ msgOUT.payload = node.valueToToggle;
29
+ setNodeStatus({ fill: "green", shape: "dot", text: "(Send) " + msgOUT.payload });
30
+ node.send(msgOUT);
31
+ } catch (error) {
32
+ setNodeStatus({ fill: "red", shape: "dot", text: "Unable to invert the input payload " + bRes });
33
+ }
34
+
35
+ });
36
+
37
+
38
+
39
+ function ToBoolean(value) {
40
+ var res = false;
41
+ var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
42
+
43
+ if (typeof value === 'boolean') {
44
+ res = value;
45
+ }
46
+ else if (typeof value === 'number' || typeof value === 'string') {
47
+
48
+ if (typeof value === "string" && value.toLowerCase() === "on") return true;
49
+ if (typeof value === "string" && value.toLowerCase() === "off") return false;
50
+
51
+ // Is it formated as a decimal number?
52
+ if (decimal.test(value)) {
53
+ var v = parseFloat(value);
54
+ res = v != 0;
55
+ }
56
+ else {
57
+ res = value.toLowerCase() === "true";
58
+ }
59
+ }
60
+
61
+ return res;
62
+ };
63
+
64
+
65
+
66
+ }
67
+
68
+
69
+
70
+ RED.nodes.registerType("toggleUltimate", toggleUltimate);
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-boolean-logic-ultimate",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "A set of Node-RED enhanced boolean logic node, flow interruption node, blinker node, invert node, filter node, with persisten values after reboot and more.",
5
5
  "author": "Supergiovane (https://github.com/Supergiovane)",
6
6
  "dependencies": {
@@ -30,7 +30,8 @@
30
30
  "InjectUltimate": "boolean-logic-ultimate/InjectUltimate.js",
31
31
  "StatusUltimate": "boolean-logic-ultimate/StatusUltimate.js",
32
32
  "ImpulseUltimate": "boolean-logic-ultimate/ImpulseUltimate.js",
33
- "SumUltimate": "boolean-logic-ultimate/SumUltimate.js"
33
+ "SumUltimate": "boolean-logic-ultimate/SumUltimate.js",
34
+ "toggleUltimate": "boolean-logic-ultimate/toggleUltimate.js"
34
35
  }
35
36
  }
36
37
  }