選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FilterUltimate.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. module.exports = function(RED) {
  2. function FilterUltimate(config) {
  3. RED.nodes.createNode(this,config);
  4. this.config = config;
  5. var node = this;
  6. setNodeStatus( {fill: "grey" ,shape: "dot" ,text: "Waiting"});
  7. this.on('input', function (msg) {
  8. var sTopic = node.config.name;
  9. if (msg.hasOwnProperty("topic")){
  10. sTopic = (msg.topic === "" ? sTopic : msg.topic);
  11. }
  12. if (typeof msg.payload !== "undefined") {
  13. var bRes = ToBoolean(msg.payload);
  14. if (typeof bRes === "undefined") return;
  15. var msgTrue = {
  16. topic: sTopic,
  17. payload: true
  18. };
  19. var msgFalse = {
  20. topic: sTopic,
  21. payload: false
  22. };
  23. if (bRes === true) {
  24. setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) true,null"});
  25. node.send([msgTrue, null]);
  26. } else
  27. {
  28. setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) null,false"});
  29. node.send([null, msgFalse]);
  30. }
  31. return;
  32. }
  33. });
  34. function setNodeStatus({fill, shape, text})
  35. {
  36. var dDate = new Date();
  37. node.status({fill: fill,shape: shape,text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")"})
  38. }
  39. function ToBoolean( value ) {
  40. var res = false;
  41. if (typeof value === 'boolean') {
  42. res = value;
  43. }
  44. else if( typeof value === 'number' || typeof value === 'string' ) {
  45. // Is it formated as a decimal number?
  46. if( decimal.test( value ) ) {
  47. var v = parseFloat( value );
  48. res = v != 0;
  49. }
  50. else {
  51. res = value.toLowerCase() === "true";
  52. }
  53. }
  54. return res;
  55. };
  56. }
  57. RED.nodes.registerType("FilterUltimate",FilterUltimate);
  58. }