Lock Management

Last Updated on : 2024-11-22 02:19:31download

This topic describes how to manage a lock.

Get the list of added locks

API description

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

Parameters

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 the lock device list successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to get the 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(IThingResultCallback<LockDetailBean> callback);

Parameters

Parameter Description
callback The callback.

Example

ThingOSLock.newLockInstance(siteId, deviceId).getLockDetail (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
    }
});

Fields in LockDeviceBean

Field Description
deviceId The device ID of the lock.
deviceName The device name of the lock.
gatewayId The device ID of the gateway connected to the lock. The value is null if there is no gateway.
gatewayName The device name of the gateway connected to the lock. The value is null if there is no gateway.
deviceType The type of the lock.
  • single-ble: A Bluetooth Low Energy (LE) lock, with no gateway connected.
  • gateway-device: A lock connected to a gateway.
online The connection status of the lock on the internet.
  • true: Online
  • false: Offline
electricQuantity The lock’s battery level.
deviceRole The role of the current user.
  • owner: Device owner
  • admin: Device admin
  • member: Common user
supportAbilities The capabilities supported by the lock, including:
  • e-key: E-key
  • offline-passcode: Offline password
  • temporary-passcode: Online password
  • card: Card
  • fingerprint: Fingerprint
  • admin: Admin
  • log: Device logs
  • remote-unlock: Remote unlocking
  • setting: Settings
  • remote-close: Remote locking
livecycleType Password validity
  • permanent: Permanent
  • periodicity: Time-limited
  • once: One-time
timeScheduleInfo The device time setting.
eKeyId The ID of the e-key.
automaticLock Whether the device supports auto-locking.
closedOpenedState The current open/closed status.
manualCloseFlag Whether the device supports manual locking in the current status.
  • true: Support
  • false: Not support
reverseLockState The double locking status.
  • -1: Unknown
  • 1: Double locked
  • 0: Not double locked
connectionStatus The current connection status.
isSupportOta Whether OTA updates are supported.
timeZoneId The time zone of the device.
account The account associated with the device.

Unlock a door

API description

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

Parameters

Parameter Description
callback The unlocking callback.

Example

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

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

Lock a door

API description

ILockDevice # void lock(IThingResultCallback<Boolean> callback);

Parameters

Parameter Description
callback The locking callback.

Example

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

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

  • The execution of manual locking depends on several factors, such as DP configuration, double locking status, door status, and auto-locking status.
  • Before calling the lock method, it is recommended to verify if manual locking is supported by checking the manualCloseFlag in LockDetailBean.
    • true: Manual locking is supported.
    • false: Manual locking is not supported.

Rename a lock

API description

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

Parameters

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

Example

ThingOSLock.newLockInstance(siteId, 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);

Parameters

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
    }
});

To remove a lock using this method, the lock must be online. Otherwise, it cannot be deleted.

Force delete a lock

API description

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

Parameters

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

Example

ThingOSLock.newSiteInstance(siteId).forceDeleteLock(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
    }
});

  • If a device malfunctions or fails to connect, you can use this method to remove it.
  • Calling this method while the device is offline will not delete any data that has already been written. Manually reset the device when needed to activate pairing mode.

Set auto-locking on/off

API description

ILockDevice # void setAutoLockSwitch(boolean autoLockEnable, IThingResultCallback<Boolean> callback);

Parameters

Parameter Description
autoLockEnable Whether the device enables auto-locking.
callback The callback for enabling auto-locking.

Example

ThingOSLock.newLockInstance(siteId, deviceId).setAutoLockSwitch(true, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Enabled auto-lock successfully
    }

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

Check support for auto-locking

API description

ILockDevice # boolean isSupportAutoLock();

Parameters

Parameter Description
Return value Whether the device supports auto-locking.
  • true: Support
  • false: Not support

Example

 ThingOSLock.newLockInstance(siteId, deviceId).isSupportAutoLock()