E-Key Management

Last Updated on : 2024-03-20 09:50:23download

This topic describes how to manage an e-key.

Get the list of e-keys

API description

ILockDevice # void getEKeyList(EKeyListParams params, IThingResultCallback<EKeyListResp> callback);

Parameter description

Parameter Description
params The parameter bean for requesting the e-key list.
params.groupId The site ID. Pass the siteId.
params.deviceId The device ID of the lock.
params.ekeyName The name of the e-key.
params.periodType The type of the time range.
params.pageNo The page number.
params.pageSize The number of items returned per page.
callback The callback.

Example

EKeyListParams params = new EKeyListParams();
params.groupId = siteId;
params.pageNo = 1;
params.pageSize = 20;
params.deviceId = deviceId;
ThingOSLock.newLockInstance(deviceId).getEKeyList(params, new IThingResultCallback<EKeyListResp>() {
    @Override
    public void onSuccess(EKeyListResp result) {
        // Got ekey list successfully
    }

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

Create a permanent e-key

API description

ILockDevice # void createPermanentEKey(PermanentEKeyCreateParams params, IThingResultCallback<EKeyResp> callback);

Parameter description

Parameter Description
params The parameter bean for creating a permanent e-key.
params.countryCode The country code of the account logged in to the app, for example, 86 for China.
params.deviceId The device ID of the lock.
params.siteId The ID of the site to which the lock belongs.
params.ekeyName The name of the e-key.
params.account The account of the e-key, which can be a mobile phone number or an email address.
callback The callback.

Example

PermanentEKeyCreateParams params = new PermanentEKeyCreateParams();
params.account = "xxx@163.com"
params.countryCode = "86";
params.ekeyName = "Test EKey Name";
params.deviceId = deviceId;
params.siteId = siteId;
ThingOSLock.newLockInstance(deviceId).createPermanentEKey(params, new IThingResultCallback<EKeyResp>() {
    @Override
    public void onSuccess(EKeyResp result) {
        //Created permanent ekey successfully
    }

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

Create a time-limited e-key

API description

ILockDevice # void createPeriodicityEKey(PeriodicityEKeyCreateParams params, IThingResultCallback<EKeyResp> callback);

Parameter description

Parameter Description
params The parameter bean for creating a time-limited e-key.
params.countryCode The country code of the account logged in to the app, for example, 86 for China.
params.deviceId The device ID of the lock.
params.siteId The ID of the site to which the lock belongs.
params.ekeyName The name of the e-key.
params.account The account of the e-key, which can be a mobile phone number or an email address.
params.effectiveTime The timestamp when the e-key becomes active, in milliseconds.
params.invalidTime The timestamp when the e-key expires, in milliseconds.
params.workingDay The schedule, a 7-bit string, with each bit being either 0 or 1.
0 indicates the schedule is off, while 1 indicates it is on. The bits from left to right represent Sunday through Saturday.
params.startMinuteFormat The start time for access, a string in the format of hh:mm. For example, 03:30 indicates the e-key becomes active at 03:30.
params.endMinuteFormat The end time for access, a string in the format of hh:mm. For example, 18:30 indicates the e-key becomes inactive at 18:30.
callback The callback.

Example

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

PeriodicityEKeyCreateParams params = new PeriodicityEKeyCreateParams();
params.account = "xxx@163.com";
params.countryCode = "86";
params.ekeyName = "Account name";
params.deviceId = deviceId;
params.siteId = siteId;
try {
    params.effectiveTime = dateFormat.parse("2023-03-01 10:00:00").getTime();
    params.invalidTime = dateFormat.parse("2024-01-02 18:00:00").getTime();
} catch (ParseException e) {

}
params.startMinuteFormat = startTimeEditText.getText().toString().trim();
params.endMinuteFormat = endTimeEditText.getText().toString().trim();
params.workingDay = getWorkingDay();
ThingOSLock.newLockInstance(deviceId).createPeriodicityEKey(params, new IThingResultCallback<EKeyResp>() {
    @Override
    public void onSuccess(EKeyResp result) {
        //Created time-limited ekey successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to create time-limited ekey
    }
});

Create a one-time e-key

API description

ILockDevice # void createOnceEKey(OnceEKeyCreateParams params, IThingResultCallback<EKeyResp> callback);

Parameter description

Parameter Description
params The parameter bean for creating a one-time e-key.
params.countryCode The country code of the account logged in to the app, for example, 86 for China.
params.deviceId The device ID of the lock.
params.siteId The ID of the site to which the lock belongs.
params.ekeyName The name of the e-key.
params.account The account of the e-key, which can be a mobile phone number or an email address.
callback The callback.

Example

OnceEKeyCreateParams params = new OnceEKeyCreateParams();
params.account = "xxx@163.com";
params.countryCode = "86";
params.ekeyName = "Once EKey name";
params.deviceId = deviceId;
params.siteId = siteId;
ThingOSLock.newLockInstance(deviceId).createOnceEKey(params, new IThingResultCallback<EKeyResp>() {
    @Override
    public void onSuccess(EKeyResp result) {
        //Created one-time ekey successfully
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
        //Failed to create one-time ekey
    }
});

Get e-key details

API description

ILockDevice # void getEKeyDetail(long siteId, String eKeyId, IThingResultCallback<EKeyBean> callback);

Parameter description

Parameter Description
siteId The ID of the site to which the lock belongs.
ekeyId The ID of the e-key.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).getEKeyDetail(siteId, ekeyId, new IThingResultCallback<EKeyBean>() {
    @Override
    public void onSuccess(EKeyBean result) {
        //Got ekey details successfully
    }

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

Modify e-key information

API description

ILockDevice # void updateEKey(EKeyUpdateParams params, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
params The parameter bean for modifying e-key information.
params.deviceId The device ID of the lock.
params.groupId The ID of the site to which the lock belongs.
params.ekeyId The ID of the e-key.
params.ekeyName The name of the e-key.
params.effectiveTime The timestamp when the e-key becomes active, in milliseconds.
params.invalidTime The timestamp when the e-key expires, in milliseconds.
params.workingDay The schedule, a 7-bit string, with each bit being either 0 or 1.
0 indicates the schedule is off, while 1 indicates it is on. The bits from left to right represent Sunday through Saturday.
params.startMinute The start timestamp for access. It is calculated as: hours × 60 + minutes. For example, for 03:30, it would be 3 × 60 + 30 = 210.
params.endMinute The end timestamp for access. It is calculated as: hours × 60 + minutes. For example, for 23:59, it would be 23 × 60 + 59 = 1,439.
callback The callback.

Example

EKeyUpdateParams params =...

ThingOSLock.newLockInstance(deviceId).updateEKey(params, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Updated ekey successfully
    }

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

Delete an e-key

API description

ILockDevice # void removeEKey(long siteId, String eKeyId, IThingResultCallback<Boolean> callback);

Parameter description

Parameter Description
siteId The site ID.
ekeyId The ID of the e-key.
callback The callback.

Example

ThingOSLock.newLockInstance(deviceId).removeEKey(siteId, ekeyId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //Removed ekey successfully
    }

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