|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- module.exports = function(RED) {
- function FilterUltimate(config) {
- RED.nodes.createNode(this,config);
- this.config = config;
- var node = this;
- setNodeStatus( {fill: "grey" ,shape: "dot" ,text: "Waiting"});
- this.on('input', function (msg) {
- var sTopic = node.config.name;
- if (msg.hasOwnProperty("topic")){
- sTopic = (msg.topic === "" ? sTopic : msg.topic);
- }
-
- if (typeof msg.payload !== "undefined") {
- var bRes = ToBoolean(msg.payload);
- if (typeof bRes === "undefined") return;
- var msgTrue = {
- topic: sTopic,
- payload: true
- };
- var msgFalse = {
- topic: sTopic,
- payload: false
- };
- if (bRes === true) {
- setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) true,null"});
- node.send([msgTrue, null]);
- } else
- {
- setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) null,false"});
- node.send([null, msgFalse]);
- }
- return;
- }
- });
-
- function setNodeStatus({fill, shape, text})
- {
- node.status({fill: fill,shape: shape,text: text + " (Last " + new Date().toLocaleString() + ")"})
- }
-
-
- function ToBoolean( value ) {
- var res = false;
-
- if (typeof value === 'boolean') {
- res = value;
- }
- else if( typeof value === 'number' || typeof value === 'string' ) {
- // Is it formated as a decimal number?
- if( decimal.test( value ) ) {
- var v = parseFloat( value );
- res = v != 0;
- }
- else {
- res = value.toLowerCase() === "true";
- }
- }
-
- return res;
- };
- }
-
-
- RED.nodes.registerType("FilterUltimate",FilterUltimate);
- }
|