Lock Management

Last Updated on : 2024-03-20 09:20:07download

This topic describes how to manage a lock.

Add a lock

API description

//1. Scan for nearby Bluetooth devices.
IThingBleLockActivator # void startScan(int scanTimeOut, IThingResultCallback<ScanDeviceBean> callback);

//2. Pair the discovered Bluetooth devices.
IThingBleLockActivator # void startActivator(long siteId, ScanDeviceBean scanDeviceBean, IBleActivatorListener listener);

Parameter description

Parameter Description
siteId The site ID.
scanDeviceBean The discovered device model.
listener The callback for the result of pairing.

Example

HashMap<String, ScanDeviceBean> map = new HashMap<>();

ThingOSLock.getBleLockActivator().startScan(60 * 1000, new IThingResultCallback<ScanDeviceBean>() {
    @Override
    public void onSuccess(ScanDeviceBean result) {
        //Scanned device successfully
        if (map.get(result.getUuid()) != null) {
            return;
        }

        map.put(result.getUuid(), result);

        ThingOSLock.getBleLockActivator().startActivator(siteId, result, new IBleActivatorListener() {
            @Override
            public void onSuccess(DeviceBean deviceBean) {
                //Activated device successfully
            }

            @Override
            public void onFailure(int code, String msg, Object handle) {
                //Failed to activate device
            }
        });
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to scan device
    }
});
  • A device may trigger the callback for a device scan multiple times, so you need to handle the deduplication logic.
  • To get information about the discovered device, call IThingBleLockActivator # getActivatorDeviceInfo.
  • To exit the pairing process, call stopScan and stopActivator.

Get the list of added locks

API description

ILockSite # void getLockDeviceList(long startId, IThingResultCallback<ArrayList<DeviceBeanWrapper>> callback);

Parameter description

Parameter Description
start_id The pagination cursor. Pass 0 for the first request. On subsequent requests, its value is the gatewayIndexId of the last device returned in the previous response.
callback The callback for getting the lock list.

Example

ThingOSLock.newSiteInstance(siteId).getLockDeviceList(0L, new IThingResultCallback<ArrayList<DeviceBeanWrapper>>() {
    @Override
    public void onSuccess(ArrayList<DeviceBeanWrapper> result) {
        //Got lock device list successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to get lock device list
    }
});

  • The request for the list of locks is paginated to 20 items per page.
  • start_id represents the pagination cursor. Pass 0 for the first request. On subsequent requests, its value is the gatewayIndexId of the last device returned in the previous response.

Get lock details

API description

ILockDevice # void getLockDetail(long siteId, IThingResultCallback<LockDetailBean> callback);

Parameter description

Parameter Description
siteId The site ID.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).getLockDetail(siteId, new IThingResultCallback<LockDetailBean>() {
    @Override
    public void onSuccess(LockDetailBean result) {
        //Got lock details successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to get lock details
    }
});

Unlock the door

API description

ILockDevice # void unlock(long siteId, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
siteId The site ID.
callback The callback for unlocking the door.

Example

ThingOSLock.newLockInstance(deviceId).unlock(siteId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Unlocked successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to unlock
    }
});

Rename a lock

API description

ILockDevice # void updateName(String name, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
name The name of the lock.
callback The callback for renaming the lock.

Example

ThingOSLock.newLockInstance(deviceId).updateName(newLockName, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Updated name successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to update name
    }
});

Delete a lock

API description

ILockSite # void deleteLock(String devId, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
devId The ID of the target lock.
callback The callback for deleting the lock.

Example

ThingOSLock.newSiteInstance(siteId).deleteLock(devId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Deleted lock successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to delete lock
    }
});