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.

73 rindas
1.5KB

  1. var NodeHelper = function( node ) {
  2. var myNode = node;
  3. var self = this;
  4. var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
  5. this.ToBoolean = function( value ) {
  6. var res = false;
  7. if (typeof value === 'boolean') {
  8. res = value;
  9. }
  10. else if( typeof value === 'number' || typeof value === 'string' ) {
  11. // Is it formated as a decimal number?
  12. if( decimal.test( value ) ) {
  13. var v = parseFloat( value );
  14. res = v != 0;
  15. }
  16. else {
  17. res = value.toLowerCase() === "true";
  18. }
  19. }
  20. return res;
  21. };
  22. this.DisplayStatus = function( value ) {
  23. myNode.status(
  24. {
  25. fill: value ? "green" : "red",
  26. shape: value ? "dot" : "ring",
  27. text: value ? "true" : "false"
  28. }
  29. );
  30. };
  31. this.DisplayUnkownStatus = function() {
  32. myNode.status(
  33. {
  34. fill: "gray",
  35. shape: "dot",
  36. text: "Unknown"
  37. });
  38. };
  39. this.SetResult = function( _valueAND, _valueOR, _valueXOR, optionalTopic ) {
  40. self.DisplayStatus( "AND:" + _valueAND + " OR:" +_valueOR + " XOR:" +_valueXOR);
  41. if (_valueAND!=null){
  42. var msgAND = {
  43. topic: optionalTopic === undefined ? "result" : optionalTopic,
  44. operation:"AND",
  45. payload: _valueAND
  46. };
  47. }
  48. if (_valueOR!=null){
  49. var msgOR = {
  50. topic: optionalTopic === undefined ? "result" : optionalTopic,
  51. operation:"OR",
  52. payload: _valueOR
  53. };
  54. }
  55. if (_valueXOR!=null){
  56. var msgXOR = {
  57. topic: optionalTopic === undefined ? "result" : optionalTopic,
  58. operation:"XOR",
  59. payload: _valueXOR
  60. };
  61. }
  62. myNode.send([msgAND,msgOR,msgXOR]);
  63. };
  64. };
  65. module.exports = NodeHelper;