Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

InvertUltimate.js 1.2KB

pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module.exports = function(RED) {
  2. function InvertUltimate(config) {
  3. RED.nodes.createNode(this,config);
  4. this.config = config;
  5. var node = this;
  6. var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
  7. setNodeStatus( {fill: "grey" ,shape: "dot" ,text: "Waiting"});
  8. this.on('input', function(msg) {
  9. var topic = msg.topic || "";
  10. var payload = msg.payload;
  11. if (topic !== undefined && payload !== undefined) {
  12. setNodeStatus( {fill: "green" ,shape: "dot" ,text: "(Send) " + !ToBoolean(payload)});
  13. node.send({ topic: topic, payload: !ToBoolean(payload) });
  14. return;
  15. }
  16. });
  17. function ToBoolean( value ) {
  18. var res = false;
  19. if (typeof value === 'boolean') {
  20. res = value;
  21. }
  22. else if( typeof value === 'number' || typeof value === 'string' ) {
  23. // Is it formated as a decimal number?
  24. if( decimal.test( value ) ) {
  25. var v = parseFloat( value );
  26. res = v != 0;
  27. }
  28. else {
  29. res = value.toLowerCase() === "true";
  30. }
  31. }
  32. return res;
  33. };
  34. function setNodeStatus({fill, shape, text})
  35. {
  36. node.status({fill: fill,shape: shape,text: text + " (Last " + new Date().toLocaleString() + ")"})
  37. }
  38. }
  39. RED.nodes.registerType("InvertUltimate",InvertUltimate);
  40. }