0% found this document useful (0 votes)
131 views37 pages

Tuya BLE Lock Instructions - Tuya Smart - App Development

The document provides instructions for using the Tuya BLE Lock SDK to manage lock members, connect Bluetooth locks, get unlock records, and control lock functions through code. It includes APIs for getting lock members, creating and updating members, checking lock connection status, getting dynamic passwords, unlocking/locking via Bluetooth, and managing unlock modes.

Uploaded by

luisvaleguer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views37 pages

Tuya BLE Lock Instructions - Tuya Smart - App Development

The document provides instructions for using the Tuya BLE Lock SDK to manage lock members, connect Bluetooth locks, get unlock records, and control lock functions through code. It includes APIs for getting lock members, creating and updating members, checking lock connection status, getting dynamic passwords, unlocking/locking via Bluetooth, and managing unlock modes.

Uploaded by

luisvaleguer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Tuya BLE Lock Instructions

Android App SDK > Extension SDK > Smart Lock SDK

Version: 20201231

Online Version
Contents

Contents

1 Term Explanation 1

2 Description 2

3 Member Management 3
3.1 Get Lock Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Create Lock Member . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.3 Update Lock Member . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Delete Lock Member . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4 Device Bluetooth Connection Status 10


4.1 Determine the Lock Is Connected . . . . . . . . . . . . . . . . . . . . 10
4.2 Connect Bluetooth Door Lock . . . . . . . . . . . . . . . . . . . . . . 10

5 Dynamic Password 12
5.1 Get Dynamic Password . . . . . . . . . . . . . . . . . . . . . . . . . 12

6 Bluetooth Unlock & Lock 14


6.1 Unlock via Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6.2 Lock via Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

7 Lock Records 16
7.1 Get Alarm Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.2 Get Unlocked Records . . . . . . . . . . . . . . . . . . . . . . . . . . 18

8 Unlock Mode Management 19


8.1 Get Unlock Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8.2 Register Unlock Mode Listener . . . . . . . . . . . . . . . . . . . . . . 21
8.3 Add Unlock Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.4 Update Unlock Mode Info . . . . . . . . . . . . . . . . . . . . . . . . 28
8.5 Delete Unlock Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
8.6 Fingerprint Entry Canceled . . . . . . . . . . . . . . . . . . . . . . . 30
8.7 Update the Unlock Mode of Password Type . . . . . . . . . . . . . . . 31

9 BLE Door Lock Function Points 33

i
1 TERM EXPLANATION

1 Term Explanation

Term Explanation

dpCode The identifier of the device function


point. Each function point in the
device has a name and number.
Please refer to BLE Door Lock Function
Points

hijack Door lock hijacking refers to setting a


specific password (fingerprint,
password, etc.) as the hijacking
password.

When the user enters this password to


open the door, the door lock considers
the user to open the door involuntarily,
and sends the alarm information to the
family’s mobile phone or property
management system.

door lock member Door lock members are divided into


family members and non-family
members.

Family members are members who are


added to the user’s family. The door
lock can be used to manage family
members and set the unlock mode.

Non-family members are members


created in door locks and can be
managed through door lock related
interfaces.

lockUserId and userId lockUserId is the firmware member id


assigned to the device by the cloud
when creating the door lock member.

1 / 35
2 DESCRIPTION

Term Explanation

userId is the database record id


assigned by the cloud when creating
the door lock member, means the
user’s unique id

2 Description

Class Name Description

TuyaOptimusSdk SDK init class, used to create


ITuyaLockManager

ITuyaLockManager Lock manager class, used to create


ITuyaBleLock

ITuyaBleLock BLE door lock class, all BLE door lock


APIs are in it

Create ITuyaBleLock by device id:

1 // init sdk
2 TuyaOptimusSdk .init( getApplicationContext ());
3 // get ITuyaLockManager
4 ITuyaLockManager tuyaLockManager = TuyaOptimusSdk . getManager ( ITuyaLo
5 ckManager .class );
6 // create ITuyaBleLock
7 ITuyaBleLock tuyaLockDevice = tuyaLockManager . getBleLock ( your_device
8 _id);

2 / 35
3 MEMBER MANAGEMENT

3 Member Management

The door lock can be divided into family members and non-family members. Family
members are concepts in the whole house intelligence, you can refer to the Family
Member Management for details.

3.1 Get Lock Members

Description

1 /**
2 * get lock users
3 */
4 public void getLockUsers ( final ITuyaResultCallback <List < BLELockUser >
5 > callback )

Parameters

BLELockUser data model

Field Type Description

userId String user id

lockUserId int user id in lock device

userContact String user contact

nickName String user nick name

avatarUrl String avatar url

userType int User type, 10 is


administrator, 20 is
ordinary home user, 30
is door lock user

3 / 35
3 MEMBER MANAGEMENT

Field Type Description

supportUnlockTypes List Supported unlock types,


you can check the
unlock type in
TuyaUnlockType

effectiveTimestamp long User effective


timestamp, unit ms

invalidTimestamp long User failure timestamp,


unit ms

Example

1 tuyaLockDevice . getLockUsers (new ITuyaResultCallback <List < BLELockUser


2 >>() {
3 @Override
4 public void onError ( String code , String message ) {
5 Log.e(TAG , "get lock users failed : code = " + code + " mess
6 age = " + message );
7 }
8 @Override
9 public void onSuccess (List < BLELockUser > user) {
10 Log.i(TAG , "get lock users success : lockUserBean = " + user)
11 ;
12 }
13 });

3.2 Create Lock Member

SDK support add member for lock device

4 / 35
3 MEMBER MANAGEMENT

1 Title : create lock member


2 participant app
3 participant server
4 note over app: write member info
5 app -> server : send create member request
6 server -->app: response result
7 note over app: show result

Note: For non-family members created here, family members needs to refer to
the document Family Member Management.

Description

1 /**
2 * add lock user
3 *
4 * @param userName userName
5 * @param allowedUnlock Whether allowed unlock with bluetooth
6 * @param permanent Whether the user is permanent
7 * @param effectiveTimestamp User effective time
8 * @param invalidTimestamp User invalid time
9 * @param avatarFile avatar
10 * @param callback callback
11 */
12 void addLockUser ( final String userName , boolean allowedUnlock , boole
13 an permanent , long effectiveTimestamp , long invalidTimestamp , File a
14 vatarFile , final ITuyaResultCallback <Boolean > callback );

Parameters

Parameter Description

userName user name

allowedUnlock Allow users to unlock using Bluetooth

unlockType Unlock type, you can check


TuyaUnlockType

permanent Whether it is a permanent user

5 / 35
3 MEMBER MANAGEMENT

Parameter Description

effectiveTimestamp User effective timestamp, unit ms, if


the permanent value is true, the value
can be ignored

invalidTimestamp User expiry timestamp, unit ms, if the


permanent value is true, this value
can be ignored

avatarFile avatar file

Example

1 tuyaLockDevice . addLockUser (" your_user_name ", true , true , 0, 0, null ,


2 new ITuyaResultCallback <Boolean >() {
3 @Override
4 public void onError ( String code , String message ) {
5 Log.e(TAG , "add lock user failed : code = " + code + " messa
6 ge = " + message );
7 }
8 @Override
9 public void onSuccess ( Boolean result ) {
10 Log.i(TAG , "add lock user success ");
11 }
12 });

3.3 Update Lock Member

SDK provides the function of modifying the members of the lock. The members
of the lock will interact with the hardware and require the device to maintain a
Bluetooth connection.

6 / 35
3 MEMBER MANAGEMENT

1 Title : Update Lock Member


2 participant server
3 participant app
4 participant lock
5 note over app: write new user info
6 app ->lock: create bluetooth connection
7 app ->lock: send device update member command data
8 lock -->app: receive device update result
9 app -> server : send request , update member
10 server -->app: return result
11 note over app: show result

Description

1 /**
2 * update lock user
3 *
4 * @param userId userId
5 * @param userName userName
6 * @param allowedUnlock Whether allowed unlock with bluetooth
7 * @param permanent Whether the user is permanent
8 * @param effectiveTimestamp User effective time
9 * @param invalidTimestamp User invalid time
10 * @param avatarFile avatar
11 * @param callback callback
12 */
13 void updateLockUser ( final String userId , boolean allowedUnlock , fina
14 l String userName , final boolean permanent , long effectiveTimestamp ,
15 long invalidTimestamp , File avatarFile , final ITuyaResultCallback <B
16 oolean > callback );

Parameters

Parameter Description

userId user id

allowedUnlock Allow users to unlock using Bluetooth

userName user name

permanent Whether it is a permanent user

7 / 35
3 MEMBER MANAGEMENT

Parameter Description

effectiveTimestamp User effective timestamp, unit ms, if


the permanent value is true, the value
can be ignored

invalidTimestamp User expiry timestamp, unit ms, if the


permanent value is true, this value
can be ignored

avatarFile avatar file

Example

1 tuyaLockDevice . updateLockUser (" your_user_id ", true , " your_user_name "


2 , true , 0, 0, null , new ITuyaResultCallback <Boolean >() {
3 @Override
4 public void onError ( String code , String message ) {
5 Log.e(TAG , " update lock user failed : code = " + code + " me
6 ssage = " + message );
7 }
8 @Override
9 public void onSuccess ( Boolean aBoolean ) {
10 Log.i(TAG , " update lock user success ");
11 }
12 });

3.4 Delete Lock Member

SDK provides the feature of deleting the member of the lock. The member of the
lock will interact with the hardware and delete all unlocking methods and passwords
of the user. The operation requires the device to maintain a bluetooth connection.

8 / 35
3 MEMBER MANAGEMENT

1 Title : Delete Lock Member


2 participant server
3 participant app
4 participant lock
5 note over app: delete member
6 app ->lock: create bluetooth connection
7 app ->lock: send delete user command data
8 lock -->app: response command result
9 app -> server : send delete user reques
10 server -->app: response result
11 note over app: show result

Description

1 /**
2 * delete lock user
3 * @param user user bean
4 * @param callback callback
5 */
6 public void deleteLockUser ( BLELockUser user , final ITuyaResultCallba
7 ck <Boolean > callback )

9 / 35
4 DEVICE BLUETOOTH CONNECTION STATUS

4 Device Bluetooth Connection Status

After the Bluetooth connection is established between the mobile phone and the
device, the door lock can be opened via Bluetooth.

4.1 Determine the Lock Is Connected

Description
Determine whether the Bluetooth door lock is connected to the mobile phone.
The operations related to controlling the door lock basically need to call this interface
to judge, and the door lock must be online to operate.

1 /**
2 * @return if lock online , return true
3 */
4 public boolean isBLEConnected ()

Example

1 boolean online = tuyaLockDevice . isBLEConnected ();

4.2 Connect Bluetooth Door Lock

Description
If the door lock is not connected, call this interface to connect to the door lock

1 /**
2 * connect to lock
3 *
4 * @param connectListener callback BLE lock connect status
5 */
6 public void connect ( ConnectListener connectListener )

10 / 35
4 DEVICE BLUETOOTH CONNECTION STATUS

Parameters

ConnectListener is the callback of device connection status, onStatusChanged will return


online status.

Example

1 tuyaLockDevice . connect (new ConnectListener () {


2 @Override
3 public void onStatusChanged ( boolean online ) {
4 Log.i(TAG , " onStatusChanged online : " + online );
5 }
6 });

11 / 35
5 DYNAMIC PASSWORD

5 Dynamic Password

Use the SDK to get a dynamic password and enter it on the door lock to unlock. The
dynamic password is valid for 5 minutes.

1 title : Unlock with dynamic password


2 participant lock
3 participant user
4 participant app
5 participant server
6 app -> server : Request for dynamic password
7 server --> app: Returns dynamic password results
8 app --> user: Send password
9 note over user: Get dynamic password
10 user -> lock: Input dynamic password
11 note over lock: Execute

5.1 Get Dynamic Password

Description

1 public void getDynamicPassword ( final ITuyaResultCallback <String > cal


2 lback )

Example

12 / 35
5 DYNAMIC PASSWORD

1 tuyaLockDevice . getDynamicPassword (new ITuyaResultCallback <String >()


2 {
3 @Override
4 public void onError ( String code , String message ) {
5 Log.e(TAG , "get lock dynamic password failed : code = " + cod
6 e + " message = " + message );
7 }
8 @Override
9 public void onSuccess ( String dynamicPassword ) {
10 Log.i(TAG , "get lock dynamic password success : dynamicPasswo
11 rd = " + dynamicPassword );
12 }
13 });

13 / 35
6 BLUETOOTH UNLOCK & LOCK

6 Bluetooth Unlock & Lock

6.1 Unlock via Bluetooth

1 Title : Bluetooth Unlock


2 participant user
3 participant app
4 participant lock
5 note over app: bluetooth open , lock device connected
6 user ->app: unlock
7 app ->lock: use ble send unlock command data
8 note over lock: receive command , execute
9 lock -->app: send unlock result
10 note over app: show result

Description

After the door lock is connected with the app, you can call this interface to unlock
it.

1 /**
2 * unlock the door
3 */
4 public void unlock ( String lockUserId )

Parameters

Parameter Description

lockUserId The user id in the door lock device

All users will have a corresponding id in the door lock, the id starts from 1, and the
number will increase by one for each new user added.

Example

14 / 35
6 BLUETOOTH UNLOCK & LOCK

1 // "1" is the id of the current user in the door lock device


2 tuyaLockDevice . unlock ("1");

6.2 Lock via Bluetooth

1 Title : Bluetooth Lock


2 participant user
3 participant app
4 participant lock
5 note over app: bluetooth open , lock device connected
6 user ->app: lock
7 app ->lock: use ble send lock command data
8 note over lock: receive command , execute
9 lock -->app: send lock result
10 note over app: show result

Description

1 /**
2 * lock the door
3 */
4 public void lock ()

Example

1 tuyaLockDevice .lock ();

15 / 35
7 LOCK RECORDS

7 Lock Records

7.1 Get Alarm Records

Description

1 /**
2 * get alarm records
3 * @param offset page number
4 * @param limit item count
5 * @param callback callback
6 */
7 void getAlarmRecords (int offset , int limit , final ITuyaResultCallbac
8 k<Record > callback );

Parameters

Parameter Description

offset page offset

limit item count in one page

Parameters in callback

Record Description

Field Type Description

totalCount int total count of records

hasNext boolean has next page

datas List the list of records

DataBean Description

16 / 35
7 LOCK RECORDS

Field Type Description

userId String user id

unlockType String unlock type

userName String user name

createTime long create timestamp, unit


ms

devId String device id

unlockRelation UnlockRelation The relationship


between the unlock type
and the unlock password
number, if it is not the
unlock record, it can be
empty

tags int record tag,0 means


other, 1 means hijack
alarm

Example

1 tuyaLockDevice . getAlarmRecords (0, 10, new ITuyaResultCallback < Recor


2 d >() {
3 @Override
4 public void onError ( String code , String message ) {
5 Log.e(TAG , "get lock records failed : code = " + code + " me
6 ssage = " + message );
7 }
8 @Override
9 public void onSuccess ( Record recordBean ) {
10 Log.i(TAG , "get lock records success : recordBean = " + recor
11 dBean );
12 }
13 });

17 / 35
7 LOCK RECORDS

7.2 Get Unlocked Records

Description

1 /**
2 * get unlock records
3 * @param unlockTypes unlock type list
4 * @param offset page number
5 * @param limit item count
6 * @param callback callback
7 */
8 void getUnlockRecords (int offset , int limit , final ITuyaResultCallba
9 ck <Record > callback );

Parameters

Parameter Description

offset page offset

limit item count in one page

Example

1 tuyaLockDevice . getUnlockRecords (0, 10, new ITuyaResultCallback < Recor


2 d >() {
3 @Override
4 public void onError ( String code , String message ) {
5 Log.e(TAG , "get unlock records failed : code = " + code + "
6 message = " + message );
7 }
8 @Override
9 public void onSuccess ( Record recordBean ) {
10 Log.i(TAG , "get unlock records success : recordBean = " + rec
11 ordBean );
12 }
13 });

18 / 35
8 UNLOCK MODE MANAGEMENT

8 Unlock Mode Management

This section provides interfaces for setting, modifying, and deleting unlocking meth-
ods.

The following figure shows the interactive process of adding an unlock method:

1 sequenceDiagram
2 SDK ->>Lock: Connect
3 Note left of Lock: Connect via Bluetooth
4 Lock -->>SDK: Connect success
5 SDK ->>Lock: Add unloack mode
6 Lock -->>SDK: Success
7 SDK ->> Server : Notify to server
8 loop save info
9 Server ->> Server :
10 end
11 Server -->>SDK: Success

8.1 Get Unlock Modes

Description

1 /**
2 * get unlock mode by unlockType
3 *
4 * @param unlockType unlock type { @link com.tuya. smart . optimus .lock.
5 api. TuyaUnlockType }
6 * @param callback callback
7 */
8 void getUnlockModeList ( String unlockType , final ITuyaResultCallback <
9 ArrayList <UnlockMode >> callback );

Parameters

UnlockMode data model

19 / 35
8 UNLOCK MODE MANAGEMENT

Field Type Description

userId String user id

lockUserId int user id in door lock


device

userName String user name

unlockAttr int Unlock mode attribute, 0


is the ordinary unlock
mode, 1 is the unlock
mode

userType int User type, 10 is


administrator, 20 is
ordinary home user, 30
is door lock user

unlockModeId String The id of the current


unlock mode on the
server

unlockId String The id of the current


unlock mode in the door
lock

unlockName String The name of the current


unlock mode

unlockType String unlock type,see


TuyaUnlockType

Example

20 / 35
8 UNLOCK MODE MANAGEMENT

1 tuyaLockDevice . getUnlockModeList ( TuyaUnlockType .PASSWORD , new ITuyaR


2 esultCallback <ArrayList <UnlockMode > >() {
3 @Override
4 public void onSuccess (ArrayList < UnlockMode > result ) {
5 Log.i(TAG , " getUnlockModeList onSuccess : " + result );
6 }
7 @Override
8 public void onError ( String errorCode , String errorMessage ) {
9 Log.e(TAG , " getUnlockModeList failed : code = " + errorCode +
10 " message = " + errorMessage );
11 }
12 });

8.2 Register Unlock Mode Listener

The interfaces for adding, modifying, and deleting unlocking methods are all asyn-
chronous calls and all return from this interface.

Description

1 void setUnlockModeListener ( UnlockModeListener unlockModeListener );

The code in UnlockModeListener is as follows:

21 / 35
8 UNLOCK MODE MANAGEMENT

1 public interface UnlockModeListener {


2 /**
3 * Unlock mode parameter is illegal
4 */
5 int FAILED_STATUS_ILLEGAL_ARGUMENT = -1;
6 /**
7 * The current operation does not support this unlock type
8 */
9 int FAILED_STATUS_NOT_SUPPORT_UNLOCK_TYPE = -2;
10 /**
11 * Send command failed
12 */
13 int FAILED_STATUS_SEND_ERROR = -3;
14 /**
15 * Request to server failed
16 */
17 int FAILED_STATUS_REQUEST_SERVER_ERROR = -4;
18 /**
19 * Incomplete fingerprint
20 */
21 int FAILED_STATUS_FINGERPRINT_INCOMPLETE = -5;
22 /**
23 * Server response failed
24 */
25 int FAILED_STATUS_SERVER_RESPONSE_FAILED = -6;
26 /**
27 * Door lock response failed
28 */
29 int FAILED_STATUS_LOCK_RESPONSE_FAILED = -7;
30 /* ----The following states are defined in the door lock , and the
31 return code that fails to create the unlock mode is created ----*/
32 int FAILED_STATUS_TIMEOUT = 0x00;
33 int FAILED_STATUS_FAILED = 0x01;
34 int FAILED_STATUS_REPEAT = 0x02;
35 int FAILED_STATUS_LOCK_ID_EXHAUSTED = 0x03;
36 int FAILED_STATUS_PASSWORD_NOT_NUMBER = 0x04;
37 int FAILED_STATUS_PASSWORD_WRONG_LENGTH = 0x05;
38 int FAILED_STATUS_NOT_SUPPORT = 0x06;
39 int FAILED_STATUS_ALREADY_ENTERED = 0x07;
40 int FAILED_STATUS_ALREADY_BOUND_CARD = 0x08;
41 int FAILED_STATUS_ALREADY_BOUND_FACE = 0x09;
42 int FAILED_STATUS_PASSWORD_TOO_SIMPLE = 0x0A;
43 int FAILED_STATUS_WRONG_LOCK_ID = 0xFE;
44 /**
45 * Callback methods for adding , deleting , and modifying door
46 *
47 * @param devId device id
48 * @param userId user id
49 * @param unlockModeResponse unlockModeResponse
50 */
51 void onResult ( String devId , String userId , UnlockModeResponse un
52 lockModeResponse );
53 }

22 / 35
8 UNLOCK MODE MANAGEMENT

Parameters

Field Type Description

unlockMethod String The current method of


operating the door lock
has three values:

/** Add unlock mode */


public static final String
UN-
LOCK_METHOD_CREATE
= “un-
lock_method_create”;
/** Modify */

public static final String


UN-
LOCK_METHOD_MODIFY
= “un-
lock_method_modify”;

/** Delete */

public static final String


UN-
LOCK_METHOD_DELETE
= “un-
lock_method_delete”;

unlockType String unlock type,see


TuyaUnlockType

stage int The current stage of


operating the door lock
is defined in
BleLockConstant.
Details are as follows:

23 / 35
8 UNLOCK MODE MANAGEMENT

Field Type Description

int STAGE_AFTER = -2; //


After the operation door
lock is completed,
synchronize the data
with the server

int STAGE_BEFORE =
-1;// Before interacting
with the door lock, such
as sending commands
and interacting with the
server

int STAGE_START =
0x00; // start

int STAGE_CANCEL =
0xFE;// cancel

int STAGE_FAILED =
0xFD;// failed

int STAGE_ENTERING =
0xFC;// entering

int STAGE_SUCCESS =
0xFF;// success

lockUserId int user id in door lock


device

unlockId int Unlock mode id in door


lock device

unlockModeId String Unlock mode id

admin boolean Is it an administrator

24 / 35
8 UNLOCK MODE MANAGEMENT

Field Type Description

times int 0 means permanently


effective, 1 ~ 254
means actual effective
times, other numbers
are invalid

status int Failed status code, see


UnlockModeListener

failedStage int The stage at which the


failure occurred.

Example

25 / 35
8 UNLOCK MODE MANAGEMENT

1 tuyaLockDevice . setUnlockModeListener (new UnlockModeListener () {


2 @Override
3 public void onResult ( String devId , String userId , UnlockModeRespon
4 se unlockModeResponse ) {
5 Log.i(TAG , " UnlockModeListener devId : " + devId );
6 Log.i(TAG , " UnlockModeListener userId : " + userId );
7 Log.i(TAG , " UnlockModeListener unlockType : " + unlockModeRespons
8 e. unlockType );
9 Log.d(TAG , " UnlockModeListener : " + unlockModeResponse );
10 if ( unlockModeResponse . success ) {
11 if ( TextUtils . equals ( unlockModeResponse . unlockMethod , UnlockMo
12 deResponse . UNLOCK_METHOD_CREATE )) {
13 Log.i(TAG , " Create unlock mode success ");
14 } else if ( TextUtils . equals ( unlockModeResponse . unlockMethod , U
15 nlockModeResponse . UNLOCK_METHOD_MODIFY )) {
16 Log.i(TAG , " Modify unlock mode success ");
17 } else if ( TextUtils . equals ( unlockModeResponse . unlockMethod , U
18 nlockModeResponse . UNLOCK_METHOD_DELETE )) {
19 Log.i(TAG , " Delete unlock mode success ");
20 }
21 } else if ( unlockModeResponse . stage == BleLockConstant . STAGE_FAI
22 LED) {
23 if ( TextUtils . equals ( unlockModeResponse . unlockMethod , UnlockMo
24 deResponse . UNLOCK_METHOD_CREATE )) {
25 Log.w(TAG , " Create unlock mode failed .");
26 Log.w(TAG , " Create unlock mode failed reason : " + unlockMode
27 Response . status );
28 Log.w(TAG , " Create unlock mode failed stage : " + unlockModeR
29 esponse . failedStage );
30 } else if ( TextUtils . equals ( unlockModeResponse . unlockMethod , U
31 nlockModeResponse . UNLOCK_METHOD_MODIFY )) {
32 Log.w(TAG , " Modify unlock mode failed .");
33 Log.w(TAG , " Modify unlock mode failed reason : " + unlockMode
34 Response . status );
35 Log.w(TAG , " Modify unlock mode failed stage : " + unlockModeR
36 esponse . failedStage );
37 } else if ( TextUtils . equals ( unlockModeResponse . unlockMethod , U
38 nlockModeResponse . UNLOCK_METHOD_DELETE )) {
39 Log.w(TAG , " Delete unlock mode failed .");
40 Log.w(TAG , " Delete unlock mode failed reason : " + unlockMode
41 Response . status );
42 Log.w(TAG , " Delete unlock mode failed stage : " + unlockModeR
43 esponse . failedStage );
44 }
45 }
46 }
47 });

26 / 35
8 UNLOCK MODE MANAGEMENT

8.3 Add Unlock Mode

Description

1 /**
2 * Add unlock method .
3 *
4 * @param unlockType TuyaUnlockType { @link com.tuya.smart . optimus .lo
5 ck.api. TuyaUnlockType }
6 * @param user BLELockUser { @link com.tuya. smart .sdk. optimus .l
7 ock.bean.ble. BLELockUser }
8 * @param name Unlock mode name.
9 * @param password Unlock password . If it is not the password unlo
10 ck type , this field can be null
11 * @param times Number of times the unlock mode can be used. Th
12 e value range is 0 to 254 , 0 means unlimited times , and 1 ~ 254 is t
13 he actual number of times .
14 * @param isHijack Hijack flag. If it is true , a hijacking alarm w
15 ill be triggered when unlocking with this unlock mode.
16 */
17 void addUnlockMode ( final String unlockType , final BLELockUser user ,
18 String name , String password , int times , boolean isHijack );

Parameters

Parameter Description

unlockType Unlock type,see TuyaUnlockType

user BLELockUser,user data model

name Unlock mode name

password Unlock password. If it is not the


password unlock type, this field can be
null

times Number of times the unlock mode can


be used. The value range is 0 to 254,
0 means unlimited times, and 1 ~ 254
is the actual number of times.

27 / 35
8 UNLOCK MODE MANAGEMENT

Parameter Description

isHijack Hijack flag. If it is true, a hijacking


alarm will be triggered when unlocking
with this unlock mode.

Example

Add a password for home users

1 tuyaLockDevice . getHomeUsers (new ITuyaResultCallback <List < BLELockUser


2 >>() {
3 @Override
4 public void onSuccess (List < BLELockUser > result ) {
5 Log.i(TAG , " getHomeUsers onSuccess : " + result );
6 // add password unlock mode
7 tuyaLockDevice . addUnlockMode ( TuyaUnlockType .PASSWORD , result
8 .get (0) , " test_unlock_mode1 ", " 431232 ", 0, false );
9 }
10 @Override
11 public void onError ( String errorCode , String errorMessage ) {
12 Log.e(TAG , " getHomeUsers failed : code = " + errorCode + " m
13 essage = " + errorMessage );
14 }
15 });

8.4 Update Unlock Mode Info

Description

Update the name of the unlock mode and modify the hijacking mark.

This interface does not interact with the door lock, only communicates with the
server.

28 / 35
8 UNLOCK MODE MANAGEMENT

1 /**
2 * Update name and hijack flag of the unlocking method . Only update
3 server information , not communicate with door lock device
4 *
5 * @param unlockMode UnlockMode bean {@link com.tuya. smart .sdk. optim
6 us.lock.bean.ble. UnlockMode }
7 * @param name Unlock mode name
8 * @param isHijack Hijack flag. If it is true , a hijacking alarm w
9 ill be triggered when unlocking with this unlock mode.
10 */
11 void updateUnlockModeServerInfo ( UnlockMode unlockMode , String name ,
12 boolean isHijack );

Parameters

Parameter Description

unlockMode Unlock mode data model

name Unlock mode name

isHijack Hijack flag. If it is true, a hijacking


alarm will be triggered when unlocking
with this unlock mode.

Example

29 / 35
8 UNLOCK MODE MANAGEMENT

1 tuyaLockDevice . getUnlockModeList ( TuyaUnlockType . FINGERPRINT , new ITu


2 yaResultCallback <ArrayList <UnlockMode > >() {
3 @Override
4 public void onSuccess (ArrayList < UnlockMode > result ) {
5 Log.i(TAG , " getUnlockModeList onSuccess : " + result );
6 for ( UnlockMode unlockMode : result ) {
7 if ( TextUtils . equals ( unlockMode .unlockName , " test_unlock
8 _mode1 ")) {
9 tuyaLockDevice . updateUnlockModeServerInfo ( unlockMode
10 , " test_unlock2 ", false );// rename unlock mode
11 }
12 }
13 }
14 @Override
15 public void onError ( String errorCode , String errorMessage ) {
16 Log.e(TAG , " getUnlockModeList failed : code = " + errorCode +
17 " message = " + errorMessage );
18 }
19 });

8.5 Delete Unlock Mode

Description

1 /**
2 * Delete unlockMode .
3 *
4 * @param unlockMode unlockMode
5 */
6 void deleteUnlockMode ( UnlockMode unlockMode );

Example

1 tuyaLockDevice . deleteUnlockMode ( unlockMode );

8.6 Fingerprint Entry Canceled

Description

30 / 35
8 UNLOCK MODE MANAGEMENT

The fingerprint unlock mode generally requires 4 to 5 fingerprints to be entered.


If you need to cancel the fingerprint during the entry process, you can call this
interface.

1 /**
2 * Cancel fingerprint entry .
3 * <p>
4 * The fingerprint entry process will be repeated multiple times and
5 can be cancelled during the entry process .
6 *
7 * @param user BLELockUser { @link com.tuya. smart .sdk. optimus .lock.be
8 an.ble. BLELockUser }
9 */
10 void cancelFingerprintUnlockMode (final BLELockUser user);

8.7 Update the Unlock Mode of Password Type

Description
The password can be updated after the unlock mode of the password type is set.
You can call this interface to modify the password name, password, unlock times,
and hijack mark.
Note: Only the password type supports calling this interface.

1 /**
2 * Update the name , password , validity period and other information
3 of the unlocking method
4 *
5 * @param unlockMode UnlockMode bean {@link com.tuya. smart .sdk. optim
6 us.lock.bean.ble. UnlockMode }
7 * @param name Unlock mode name
8 * @param password Unlock password . If it is not the password unlo
9 ck method , this field can be null
10 * @param times Number of times the unlock mode can be used. Th
11 e value range is 0 to 254 , 0 means unlimited times , and 1 ~ 254 is t
12 he actual number of times .
13 * @param isHijack Hijack flag. If it is true , a hijacking alarm w
14 ill be triggered when unlocking with this unlock mode.
15 */
16 void updatePasswordUnlockMode ( UnlockMode unlockMode , String name , St
17 ring password , int times , boolean isHijack );

31 / 35
8 UNLOCK MODE MANAGEMENT

Parameters

Parameter Description

unlockMode Unlock mode data model

name Unlock mode name

password Unlock password, required for the


password type, other unlock types can
be empty

times The number of times the password is


valid. 0 means permanently effective,
1 ~ 254 means actual effective times,
other numbers are invalid

isHijack Hijack flag. If it is true, a hijacking


alarm will be triggered when unlocking
with this unlock mode.

Example

1 tuyaLockDevice . getUnlockModeList ( TuyaUnlockType .PASSWORD , new ITuyaR


2 esultCallback <ArrayList <UnlockMode > >() {
3 @Override
4 public void onSuccess (ArrayList < UnlockMode > result ) {
5 Log.i(TAG , " getUnlockModeList onSuccess : " + result );
6 for ( UnlockMode unlockMode : result ) {
7 if ( TextUtils . equals ( unlockMode .unlockName , " test_passwo
8 rd")) {
9 tuyaLockDevice . updatePasswordUnlockMode ( unlockMode ,
10 " test_password ", " 131232 ", 0, false );// modify password
11 }
12 }
13 }
14 @Override
15 public void onError ( String errorCode , String errorMessage ) {
16 Log.e(TAG , " getUnlockModeList failed : code = " + errorCode +
17 " message = " + errorMessage );
18 }
19 });

32 / 35
9 BLE DOOR LOCK FUNCTION POINTS

9 BLE Door Lock Function Points

dp name dp code

create unlock method unlock_method_create

delete unlock method unlock_method_delete

modify unlock method unlock_method_modify

disable unlock method unlock_method_freeze

enable unlock method unlock_method_enable

blue tooth unlock feedback bluetooth_unlock_fb

unlock by bluetooth bluetooth_unlock

query bluetooth unlock record unlock_ble

query fingerprint unlock record unlock_fingerprint

query password unlock record unlock_password

query temporary unlock record unlock_temporary

query dynamic unlock record unlock_dynamic

query card unlock record unlock_card

query face unlock record unlock_face

query key unlock record unlock_key

query eye unlock record unlock_eye

query hand unlock record unlock_hand

query finger vein unlock record unlock_finger_vein

alarm record alarm_lock

apply remote unlock unlock_request

reply remote unlock reply_unlock_request

battery status battery_state

33 / 35
9 BLE DOOR LOCK FUNCTION POINTS

dp name dp code

residual electricity residual_electricity

lock from inside reverse_lock

child lock status child_lock

automatic lock switch automatic_lock

Synchronized member opening synch_member


method

Auto lock delay time setting auto_lock_time

auto lock timer auto_lock_timer

finger input times finger_input_times

doorbell song selete doorbell_song

doorbell volume doorbell_volume

language language

lock welcome words welcome_words

door opened status door_opened

key volume key_tone

beep volume beep_volume

rtc lock rtc_lock

auto lock countdown time auto_lock_countdown

manual lock manual_lock

lock motor status lock_motor_state

lock motor direction lock_motor_direction

disable unlock user unlock_user_freeze

enable unlock user unlock_user_enable

create temporary password temporary_password_creat

34 / 35
9 BLE DOOR LOCK FUNCTION POINTS

dp name dp code

delete temporary password temporary_password_delete

modify temporary password temporary_password_modify

sync unlock method synch_method

motor torque motor_torque

unlock method combination unlock_double

arming mode switch arming_mode

set remote no password unlock remote_no_pd_setkey

remote no password unlock remote_no_dp_key

remote phone unlock report unlock_phone_remote

remote vioce unlock report unlock_voice_remote

password offline time password_offline_time

door open close event open_close

hijack alarm record hijack

open the door from inside open_inside

door opening and closing status closed_opened

doorbell alarm record doorbell

SMS notifacation message

lock from outside anti_lock_outside

offline password unlock report unlock_offline_pd

offline password clear report unlock_offline_clear

single offline password clear report unlock_offline_clear_single

35 / 35

You might also like