public void pairSlaves(String masterName, String adminKey, int keySlaveId, int pairSlaveId) {
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executePairSlaves(masterName, adminKey, keySlaveId, pairSlaveId);
 }
 public void readAllPermissions(Master master, Slave slave, String permissionKey) {
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executeReadAllPermissions(master.getName(), slave.getId(), permissionKey);
 }
 public void getSlaves(Master master, String permissionKey) {
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executeGetSlaves(master, permissionKey);
 }
 public void makeFirstAdminConnection(String permissionKey, String defaultKey, Master master) {
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executeFirstConnectionConfiguration(defaultKey, permissionKey, master);
 }
 public void deletePermission(String masterId, String adminKey, Permission permission) {
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executeDeletePermission(masterId, adminKey, permission);
 }
 public void editPermission(
     Permission toEditPermission, int oldSlaveId, String adminKey, String doorId) {
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executeEditPermission(toEditPermission, oldSlaveId, adminKey, doorId);
 }
  public void createNewPermission(Permission permission, String permissionKey, String masterId) {
    mBluetoothClient = BluetoothClient.getInstance(mContext, this);

    if (!mBluetoothClient.isSupported()) {
      mBluetoothListener.bluetoothNotSupported();
      return;
    } else if (!mBluetoothClient.isEnabled()) {
      mBluetoothListener.enableBluetooth();
      return;
    }

    mBluetoothClient.executeCreateNewPermission(permission, permissionKey, masterId);
  }
  public void scanDevices() {
    mBluetoothClient = BluetoothClient.getInstance(mContext, this);

    if (!mBluetoothClient.isSupported()) {
      mBluetoothListener.bluetoothNotSupported();
      return;
    } else if (!mBluetoothClient.isEnabled()) {
      mBluetoothListener.enableBluetooth();
      return;
    }

    mBluetoothClient.scanDevices();
  }
 public void openWhenClose(Master master, Slave slave, String key) {
   Permission p = slave.getPermission(this);
   if (p == null || !p.isValid()) {
     mPermissionsListener.error(BluetoothClient.DONT_HAVE_PERMISSION);
     return;
   }
   mBluetoothClient = BluetoothClient.getInstance(mContext, this);
   if (!mBluetoothClient.isSupported()) {
     mBluetoothListener.bluetoothNotSupported();
     return;
   } else if (!mBluetoothClient.isEnabled()) {
     mBluetoothListener.enableBluetooth();
     return;
   }
   mBluetoothClient.executeOpenDoorWhenClose(p.getKey(), master.getName(), slave.getId());
 }
  /** Opens a door if the user has a valid permission. */
  public void openDoor(Master master, Slave slave) {

    Permission permission = getValidPermission(master, slave);
    if (permission == null) {
      mPermissionsListener.error(BluetoothClient.DONT_HAVE_PERMISSION);
      return;
    }

    mBluetoothClient = BluetoothClient.getInstance(mContext, this);

    if (!mBluetoothClient.isSupported()) {
      mBluetoothListener.bluetoothNotSupported();
      return;
    } else if (!mBluetoothClient.isEnabled()) {
      mBluetoothListener.enableBluetooth();
      return;
    }
    mMasterListener.doorOpening();
    mBluetoothClient.executeOpenDoor(permission, master.getId(), slave.getId());
  }