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

    this.api = api

    var cryptoKey = Buffer.from(config.key.replace(/-/g, ''), 'hex');

    this.plejd = new Plejd(cryptoKey, log)
    this.plejd.on('updateDevice', this.updateDeviceFromPlejd.bind(this))

    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() {
        // Setup
        for (const device of config.devices) {
          this.addAccessory(device)
        }
      }.bind(this));
    }
}
// api may be null if launched from old homebridge version
api may be null if launched from old homebridge version
api may be null if launched from old homebridge version
function PlejdPlatform(log, config, api) {
    var platform = this;
    this.log = log;
    this.config = config;
    this.accessories = [];
    this.api = api
    var cryptoKey = Buffer.from(config.key.replace(/-/g, ''), 'hex');
    this.plejd = new Plejd(cryptoKey, log)
    this.plejd.on('updateDevice', this.updateDeviceFromPlejd.bind(this))
    if (api) {
      this.api = api;
      this.api.on('didFinishLaunching', function() {
        for (const device of config.devices) {
          this.addAccessory(device)
        }
      }.bind(this));
    }
}
function PlejdPlatform ( log , config , api ) { var platform = this ; this . log = log ; this . config = config ; this . accessories = [ ] ; this . api = api var cryptoKey = Buffer . from ( config . key . replace ( / - / g , '' ) , 'hex' ) ; this . plejd = new Plejd ( cryptoKey , log ) this . plejd . on ( 'updateDevice' , this . updateDeviceFromPlejd . bind ( this ) ) if ( api ) { this . api = api ; this . api . on ( 'didFinishLaunching' , function ( ) { for ( const device of config . devices ) { this . addAccessory ( device ) } } . bind ( this ) ) ; } }
api may be null if launched from old homebridge version
api may be null if launched from old homebridge version
// Save the API object as plugin needs to register new accessory via this object // 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. // Setup