function SamplePlatform(log, config, api) {
  log("SamplePlatform Init");
  var platform = this;
  this.log = log;
  this.config = config;
  this.accessories = [];

  this.requestServer = http.createServer(function(request, response) {
    if (request.url === "/add") {
      this.addAccessory(new Date().toISOString());
      response.writeHead(204);
      response.end();
    }

    if (request.url == "/reachability") {
      this.updateAccessoriesReachability();
      response.writeHead(204);
      response.end();
    }

    if (request.url == "/remove") {
      this.removeAccessory();
      response.writeHead(204);
      response.end();
    }
  }.bind(this));

  this.requestServer.listen(18081, function() {
    platform.log("Server Listening...");
  });

  if (api) {
      // Save the API object as plugin needs to register new accessory via this object
      this.api = api;

      // Listen to event "didFinishLaunching", this means homebridge already finished loading cached accessories.
      // Platform Plugin should only register new accessory that doesn't exist in homebridge after this event.
      // Or start discover new accessories.
      this.api.on('didFinishLaunching', function() {
        platform.log("DidFinishLaunching");
      }.bind(this));
  }
}
function SamplePlatform(log, config, api) {
  log("SamplePlatform Init");
  var platform = this;
  this.log = log;
  this.config = config;
  this.accessories = [];

  this.requestServer = http.createServer(function(request, response) {
    if (request.url === "/add") {
      this.addAccessory(new Date().toISOString());
      response.writeHead(204);
      response.end();
    }

    if (request.url == "/reachability") {
      this.updateAccessoriesReachability();
      response.writeHead(204);
      response.end();
    }

    if (request.url == "/remove") {
      this.removeAccessory();
      response.writeHead(204);
      response.end();
    }
  }.bind(this));

  this.requestServer.listen(18081, function() {
    platform.log("Server Listening...");
  });

  if (api) {
      // Save the API object as plugin needs to register new accessory via this object
      this.api = api;

      // Listen to event "didFinishLaunching", this means homebridge already finished loading cached accessories.
      // Platform Plugin should only register new accessory that doesn't exist in homebridge after this event.
      // Or start discover new accessories.
      this.api.on('didFinishLaunching', function() {
        platform.log("DidFinishLaunching");
      }.bind(this));
  }
}
function SamplePlatform ( log , config , api ) { log ( "SamplePlatform Init" ) ; var platform = this ; this . log = log ; this . config = config ; this . accessories = [ ] ; this . requestServer = http . createServer ( function ( request , response ) { if ( request . url === "/add" ) { this . addAccessory ( new Date ( ) . toISOString ( ) ) ; response . writeHead ( 204 ) ; response . end ( ) ; } if ( request . url == "/reachability" ) { this . updateAccessoriesReachability ( ) ; response . writeHead ( 204 ) ; response . end ( ) ; } if ( request . url == "/remove" ) { this . removeAccessory ( ) ; response . writeHead ( 204 ) ; response . end ( ) ; } } . bind ( this ) ) ; this . requestServer . listen ( 18081 , function ( ) { platform . log ( "Server Listening..." ) ; } ) ; if ( api ) { // Save the API object as plugin needs to register new accessory via this object this . api = api ; // Listen to event "didFinishLaunching", this means homebridge already finished loading cached accessories. // Platform Plugin should only register new accessory that doesn't exist in homebridge after this event. // Or start discover new accessories. this . api . on ( 'didFinishLaunching' , function ( ) { platform . log ( "DidFinishLaunching" ) ; } . bind ( this ) ) ; } }
Platform constructor config may be null api may be null if launched from old homebridge version
Platform constructor config may be null api may be null if launched from old homebridge version
SamplePlatform constructor.