Skip to content

Timer Management - Remote Timing

Feature Description

Device timer management supports operations such as creating, editing, deleting, querying a list of timed tasks, and querying details of timed tasks.

kotlin
QuecDeviceService

Timer Management - Remote Timing

Create Timed Task

API

Create a timed task.

kotlin
fun addCornJob(
    cornJobModel: QuecCornJobModel,
    callback: QuecCallback<String>
)

Parameter

ParameterRequiredDescription
cornJobModelYQuecCornJobModel class
callbackYCallback function of the request.

QuecCornJobModel Definition

FieldTypeDescription
createTimelongCreation time.
productKeyStringProductKey.
deviceKeyStringDeviceKey.
ruleIdStringRule ID, required when you modify rule instance information.
typeStringTimed task type.
once: execute once
day-repeat: repeat daily
custom-repeat: custom repeat
multi-section: multi-segment execution
random: execute randomly
delay: delayed execution - countdown
enabledbooleanStatus of timed tasks.
false-Stopped (default)
true-Started
dayOfWeekStringExecution day, required when type = custom-repeat. You can select multiple days and separate them by commas.
1-Monday
2-Tuesday
3-Wednesday
4-Thursday
5-Friday
6-Saturday
7-Sunday
timersList<QuecCornTimersModel>Details of the timed task.

QuecCornTimersModel Definition

FieldTypeDescription
actionStringCommand to execute the timed task. Format: JSON string in TSL model.
delaylongDelayed execution time, required when type = delay. Unit: second.
endTimeStringEnd time, required when type = random. Format: "HH:mm:ss", such as "12:00:00".
startTimeStringStart time, required when type = random. Format: "HH:mm:ss", such as "12:00:00".
timeStringExecution time, required when type = once, day-repeat, custom-repeat, multi-section. Format: "HH:mm:ss".
day-repeatcustom-repeatRequired when type = multi-section.
timerIdStringID of the timed task.

Example

kotlin
QuecDeviceService.addCornJob(
    QuecCornJobModel(
        System.currentTimeMillis(),
        "pk",
        "dk",
        "ruleId",
        "once",
        true,
        "1",
        listOf(
            QuecCornJobModel.QuecCornTimersModel(
                action = "[{\"modelCode\":\"switch\",\"modelName\":\"switch\",\"modelType\":\"PROPERTY\",\"dataType\":\"BOOL\",\"value\":\"true\",\"unit\":\"\"}]",
                delay = 0,
                timerId = "11:00:00"
            )
        )
    )
) {
    if (it.isSuccess) {
        val data = it.data //Create a timed task successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg //Failed. Error message.
    }
}

Edit Timed Task

API

Edit a timed task.

kotlin
fun setCronJob(
    cornJobModel: QuecCornJobModel,
    callback: QuecCallback<Unit>
)

Parameter

ParameterRequiredDescription
cornJobModelYQuecCornJobModel class.
callbackYCallback function of the request.

See QuecCornJobModel Definition above.

Example

kotlin
val job = getJob()  //Get a timed task from the platform.
job.enabled = false
QuecDeviceService.setCronJob(job) {
    if (it.isSuccess) {
        //Edit the timed task successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg //Failed. Error message.
    }
}

Query Timed Task List

API

Query the list of timed tasks under a device.

kotlin
fun getCronJobList(
    deviceKey: String,
    productKey: String,
    type: String?,
    pageNumber: Int,
    pageSize: Int,
    callback: QuecCallback<QuecPageResponse<QuecCornJobModel>>
)

Parameter

ParameterRequiredDescription
productKeyYProductKey.
deviceKeyYDeviceKey.
typeNTimed task type.
once: execute once
day-repeat: repeat daily
custom-repeat: custom repeat
multi-section: multi-segment execution
random: execute randomly
delay: delayed execution - countdown
pageNumberNPage number. Default value: 1.
pageSizeNPage size. Default value: 10.
callbackYCallback function of the request.

See QuecCornJobModel Definition above.

Example

kotlin
QuecDeviceService.getCronJobList("dk", "pk", null, 1, 10) {
    if (it.isSuccess) {
        val data = it.data //Query the list of timed tasks under a device successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg //Failed. Error message.
    }
}

Query Timed Task Details

API

Query the details of a timed task.

kotlin
fun getCronJobInfo(
    ruleId: String,
    callback: QuecCallback<QuecCornJobModel>
)

Parameter

ParameterRequiredDescription
ruleIdYTimed task ID.
callbackYCallback function of the request.

See QuecCornJobModel Definition above.

Example

kotlin
QuecDeviceService.getCronJobInfo("ruleId") {
    if (it.isSuccess) {
        val data = it.data //Query the details of a timed task successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg //Failed. Error message.
    }
}

Delete Timed Tasks in Batches

API

Delete timed tasks in batches.

kotlin
fun batchDeleteCornJob(
    ruleIdList: List<String>,
    callback: QuecCallback<QuecCornJobDeleteListModel>
)

Parameter

ParameterRequiredDescription
paramsYArray of timed task IDs.
callbackYCallback function of the request.

QuecCornJobDeleteListModel Definition

FieldTypeDescription
successListList<QuecCornJobDeleteModel>List of successful executions.
failureListList<QuecCornJobDeleteModel>List of failed executions.

QuecCornJobDeleteModel Definition

FieldTypeDescription
codeStringCode.
msgStringPrompt message.
ruleIdStringTimed task ID.

Example

kotlin
QuecDeviceService.batchDeleteCornJob(listOf("ruleId")) {
    if (it.isSuccess) {
        val data = it.data //Delete timed tasks in batches successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg //Failed. Error message.
    }
}

Query Maximum Number of Timed Tasks

API

Query the maximum number of timed tasks under a product.

kotlin
fun getProductCornJobLimit(
    productKey: String,
    callback: QuecCallback<Int>
)

Parameter

ParameterRequiredDescription
productKeyYProductKey.
callbackYCallback function of the request.

Example

kotlin
QuecDeviceService.getProductCornJobLimit("pk") {
    if (it.isSuccess) {
        val data = it.data //Query the maximum number of timed tasks under a product successfully.
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg //Failed. Error message.
    }
}