index.js
/**
 * Initializes a new platform instance for the nello plugin.
 * @param log The logging function.
 * @param config The configuration that is passed to the plugin (from the config.json file).
 * @param api The API instance of homebridge (may be null on older homebridge versions).
 */
Initializes a new platform instance for the nello plugin.
@param log The logging function.
@param config The configuration that is passed to the plugin (from the config.json file).
@param api The API instance of homebridge (may be null on older homebridge versions).
Initializes a new platform instance for the nello plugin . @param log The logging function . @param config The configuration that is passed to the plugin ( from the config . json file ) . @param api The API instance of homebridge ( may be null on older homebridge versions ) .
function NelloPlatform(log, config, api) {
  const platform = this;
  platform.Accessory = homebridgeObj.platformAccessory;
  platform.Categories = homebridgeObj.hap.Accessory.Categories;
  platform.Service = homebridgeObj.hap.Service;
  platform.Characteristic = homebridgeObj.hap.Characteristic;
  platform.UUIDGen = homebridgeObj.hap.uuid;
  platform.hap = homebridgeObj.hap;
  platform.pluginName = pluginName;
  platform.platformName = platformName;
  if (!config) {
    return;
  }
  platform.log = log;
  platform.config = config;
  platform.token = null;
  platform.locations = [];
  platform.accessories = [];
  platform.config.apiUri = "https://public-api.nello.io/v1";
  platform.config.authUri = "https://auth.nello.io";
  platform.config.publicWebhookUrl = platform.config.publicWebhookUrl || '';
  platform.config.webhookServerPort = platform.config.webhookServerPort || 5000;
  platform.config.authType = platform.config.authType || 'password';
  platform.config.lockTimeout = platform.config.lockTimeout || 5000;
  platform.config.locationUpdateInterval = platform.config.locationUpdateInterval == 0 ? 0 : (platform.config.locationUpdateInterval || 3600000);
  platform.config.exposeReachability = platform.config.exposeReachability;
  platform.config.motionTimeout = platform.config.motionTimeout || 5000;
  platform.config.video = platform.config.video || {};
  platform.config.video.stream = platform.config.video.stream || "-re -i";
  platform.config.video.snapshotImage = platform.config.video.snapshotImage || "http://via.placeholder.com/1280x720";
  platform.config.video.maxWidth = platform.config.video.maxWidth || 1280;
  platform.config.video.maxHeight = platform.config.video.maxHeight || 720;
  platform.config.video.maxFPS = platform.config.video.maxFPS || 30;
  platform.config.video.vcodec = platform.config.video.vcodec || "h264_omx";
  platform.config.video.rotate = platform.config.video.rotate || 0;
  if (api) {
    log("Homebridge API available.");
    platform.api = api;
    platform.api.on('didFinishLaunching', function () {
      platform.log("Cached accessories loaded.");
      platform.updateLocations(true, function () {
        if (platform.config.locationUpdateInterval > 0) {
          setInterval(function () {
            platform.updateLocations(true, function () { });
          }, platform.config.locationUpdateInterval);
        }
        platform.connectWebhook();
      });
    });
  } else {
    log("Homebridge API not available, please update your homebridge version!");
  }
}
function NelloPlatform ( log , config , api ) { const platform = this ; platform . Accessory = homebridgeObj . platformAccessory ; platform . Categories = homebridgeObj . hap . Accessory . Categories ; platform . Service = homebridgeObj . hap . Service ; platform . Characteristic = homebridgeObj . hap . Characteristic ; platform . UUIDGen = homebridgeObj . hap . uuid ; platform . hap = homebridgeObj . hap ; platform . pluginName = pluginName ; platform . platformName = platformName ; if ( ! config ) { return ; } platform . log = log ; platform . config = config ; platform . token = null ; platform . locations = [ ] ; platform . accessories = [ ] ; platform . config . apiUri = "https://public-api.nello.io/v1" ; platform . config . authUri = "https://auth.nello.io" ; platform . config . publicWebhookUrl = platform . config . publicWebhookUrl || '' ; platform . config . webhookServerPort = platform . config . webhookServerPort || 5000 ; platform . config . authType = platform . config . authType || 'password' ; platform . config . lockTimeout = platform . config . lockTimeout || 5000 ; platform . config . locationUpdateInterval = platform . config . locationUpdateInterval == 0 ? 0 : ( platform . config . locationUpdateInterval || 3600000 ) ; platform . config . exposeReachability = platform . config . exposeReachability ; platform . config . motionTimeout = platform . config . motionTimeout || 5000 ; platform . config . video = platform . config . video || { } ; platform . config . video . stream = platform . config . video . stream || "-re -i" ; platform . config . video . snapshotImage = platform . config . video . snapshotImage || "http://via.placeholder.com/1280x720" ; platform . config . video . maxWidth = platform . config . video . maxWidth || 1280 ; platform . config . video . maxHeight = platform . config . video . maxHeight || 720 ; platform . config . video . maxFPS = platform . config . video . maxFPS || 30 ; platform . config . video . vcodec = platform . config . video . vcodec || "h264_omx" ; platform . config . video . rotate = platform . config . video . rotate || 0 ; if ( api ) { log ( "Homebridge API available." ) ; platform . api = api ; platform . api . on ( 'didFinishLaunching' , function ( ) { platform . log ( "Cached accessories loaded." ) ; platform . updateLocations ( true , function ( ) { if ( platform . config . locationUpdateInterval > 0 ) { setInterval ( function ( ) { platform . updateLocations ( true , function ( ) { } ) ; } , platform . config . locationUpdateInterval ) ; } platform . connectWebhook ( ) ; } ) ; } ) ; } else { log ( "Homebridge API not available, please update your homebridge version!" ) ; } }
Initializes a new platform instance for the nello plugin.
Initializes a new platform instance for the nello plugin .
//Save objects for functions // Checks whether a configuration is provided, otherwise the plugin should not be initialized // Defines the variables that are used throughout the platform // Initializes the configuration // Checks whether the API object is available // Saves the API object to register new locks later on // Subscribes to the event that is raised when homebrige finished loading cached accessories // Initially updates the locations to get the locks // Starts the timer for updating locations (i.e. adding and removing locks of the user) //Connect to backend