function Device(driver , lwrfType, lWRFId, lShortName) {
 
  var self = this;
  this.lwrfType = lwrfType;
  this.lWRFId = lWRFId;

  // This device will emit data
  this.readable = true;
  // This device can be actuated
  this.writeable = true;

  this.G = lWRFId; // G is a string a represents the channel
  this.V = 0; // 0 is Ninja Blocks' device list
  this.name= lShortName;


  if(lwrfType == "Energy")
  {
    this.D = 242; // 243 is a generic Ninja Blocks energy monitor device

    process.nextTick(function()
    {

    setInterval(function()
    {
      sendRawUDPCommand(",@?\0");

    }, 30000);

    server.on("message", function (msg, rinfo)
    {
      if(debug)
      {
        console.log("LWRF Rx: " + msg + " from " + rinfo.address + ":" + rinfo.port);
      }
      var arr = msg.toString('ascii', 0, rinfo.size).split(',');
      var energy  = arr[1].toString().substr(3);


      // The ninja should return a string in the for, 0,?W=AAA,BBBB,CCCC,DDDD
      // where A is instantaneous consumption, B is ? C is today's consumption and D is yesterday's consumption
      self.emit('data', energy);
      self.emit('today',arr[3].toString());
      self.emit('yesterday',arr[4].toString());
    });

    server.on("listening", function ()
    {
      var address = server.address();
      console.log("server listening " +
      address.address + ":" + address.port);
    });

    server.bind(9761);

    
    });
  }
  else if (lwrfType == "Light")
  {
     this.D = 224;
     console.log('LWRF Registered a light: ' + lWRFId + ' Called ' + lShortName);
     self.emit('on', false);
  }
    else if (lwrfType == "Switch")
  {
     this.D = 207;
     console.log('LWRF Registered a switch: ' + lWRFId+ ' Called ' + lShortName);
     self.emit('on', false);
  }
  else
  {
    /* do nothing */
  }

  this.driver = driver;
}
/**
 * Creates a new Device Object
 *
 * @property {Boolean} readable Whether the device emits data
 * @property {Boolean} writable Whether the data can be actuated
 *
 * @property {Number} G - the channel of this device
 * @property {Number} V - the vendor ID of this device
 * @property {Number} D - the device ID of this device
 *
 * @property {Function} write Called when data is received from the Ninja Platform
 *
 * @fires data - Emit this when you wish to send data to the Ninja Platform
 */
Creates a new Device Object
@property {Boolean} readable Whether the device emits data
@property {Boolean} writable Whether the data can be actuated

@property {Number} G - the channel of this device
@property {Number} V - the vendor ID of this device
@property {Number} D - the device ID of this device

@property {Function} write Called when data is received from the Ninja Platform

@fires data - Emit this when you wish to send data to the Ninja Platform
Creates a new Device Object @property { Boolean } readable Whether the device emits data @property { Boolean } writable Whether the data can be actuated @property { Number } G - the channel of this device @property { Number } V - the vendor ID of this device @property { Number } D - the device ID of this device @property { Function } write Called when data is received from the Ninja Platform @fires data - Emit this when you wish to send data to the Ninja Platform
function Device(driver , lwrfType, lWRFId, lShortName) {
  var self = this;
  this.lwrfType = lwrfType;
  this.lWRFId = lWRFId;
  this.readable = true;
  this.writeable = true;
  this.G = lWRFId; 
  this.V = 0; 
  this.name= lShortName;
  if(lwrfType == "Energy")
  {
    this.D = 242; 
    process.nextTick(function()
    {
    setInterval(function()
    {
      sendRawUDPCommand(",@?\0");
    }, 30000);
    server.on("message", function (msg, rinfo)
    {
      if(debug)
      {
        console.log("LWRF Rx: " + msg + " from " + rinfo.address + ":" + rinfo.port);
      }
      var arr = msg.toString('ascii', 0, rinfo.size).split(',');
      var energy  = arr[1].toString().substr(3);
      self.emit('data', energy);
      self.emit('today',arr[3].toString());
      self.emit('yesterday',arr[4].toString());
    });
    server.on("listening", function ()
    {
      var address = server.address();
      console.log("server listening " +
      address.address + ":" + address.port);
    });
    server.bind(9761);
    });
  }
  else if (lwrfType == "Light")
  {
     this.D = 224;
     console.log('LWRF Registered a light: ' + lWRFId + ' Called ' + lShortName);
     self.emit('on', false);
  }
    else if (lwrfType == "Switch")
  {
     this.D = 207;
     console.log('LWRF Registered a switch: ' + lWRFId+ ' Called ' + lShortName);
     self.emit('on', false);
  }
  else
  {
  }
  this.driver = driver;
}
function Device ( driver , lwrfType , lWRFId , lShortName ) { var self = this ; this . lwrfType = lwrfType ; this . lWRFId = lWRFId ; this . readable = true ; this . writeable = true ; this . G = lWRFId ; this . V = 0 ; this . name = lShortName ; if ( lwrfType == "Energy" ) { this . D = 242 ; process . nextTick ( function ( ) { setInterval ( function ( ) { sendRawUDPCommand ( ",@?\0" ) ; } , 30000 ) ; server . on ( "message" , function ( msg , rinfo ) { if ( debug ) { console . log ( "LWRF Rx: " + msg + " from " + rinfo . address + ":" + rinfo . port ) ; } var arr = msg . toString ( 'ascii' , 0 , rinfo . size ) . split ( ',' ) ; var energy = arr [ 1 ] . toString ( ) . substr ( 3 ) ; self . emit ( 'data' , energy ) ; self . emit ( 'today' , arr [ 3 ] . toString ( ) ) ; self . emit ( 'yesterday' , arr [ 4 ] . toString ( ) ) ; } ) ; server . on ( "listening" , function ( ) { var address = server . address ( ) ; console . log ( "server listening " + address . address + ":" + address . port ) ; } ) ; server . bind ( 9761 ) ; } ) ; } else if ( lwrfType == "Light" ) { this . D = 224 ; console . log ( 'LWRF Registered a light: ' + lWRFId + ' Called ' + lShortName ) ; self . emit ( 'on' , false ) ; } else if ( lwrfType == "Switch" ) { this . D = 207 ; console . log ( 'LWRF Registered a switch: ' + lWRFId + ' Called ' + lShortName ) ; self . emit ( 'on' , false ) ; } else { } this . driver = driver ; }
Creates a new Device Object
 @property {Boolean} readable Whether the device emits data
 @property {Boolean} writable Whether the data can be actuated
Creates a new Device Object @property { Boolean } readable Whether the device emits data @property { Boolean } writable Whether the data can be actuated
// This device will emit data // This device can be actuated // G is a string a represents the channel // 0 is Ninja Blocks' device list // 243 is a generic Ninja Blocks energy monitor device // The ninja should return a string in the for, 0,?W=AAA,BBBB,CCCC,DDDD // where A is instantaneous consumption, B is ? C is today's consumption and D is yesterday's consumption /* do nothing */