Skip to content

Scene SDK: QuecSceneSdk

Feature Description

SDK supports users in enabling one or more devices to execute multiple tasks according to certain rules.

kotlin
QuecSceneService

SDK Integration Method

Note

The scene SDK depends on the core library quec-iot-sdk to run. Please integrate the core library according to the Quick Integration Guide.

Add dependencies

groovy
implementation 'com.quectel.app.sdk:quec-scene-sdk:2.14.0'

Scene Management

Get Scene List

API

Get the list of current scene.

kotlin
fun getSceneList(pageNumber: Int, pageSize: Int, callback: QuecCallback<QuecPageResponse<QuecSceneModel>>)

Parameter

ParameterRequiredDescription
pageNumberYPage number.
pageSizeYPage size.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.getSceneList(1, 10) {
    if (it.isSuccess) {
        //Get scene list successfully.
        val data = it.data  //scene list data.
    } else {
        //Failed to get scene list.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

QuecSceneModel Definition

FieldTypeDescription
fidStringFamily ID.
isCommonboolWhether the scene is common.
sceneInfoQuecSceneInfoModelScene details.

QuecSceneInfoModel Definition

FieldTypeDescription
executeResultintExecution result of the last scene.
iconStringScene icon.
idintExecution result of the scene.
metaDataListList<QuecMetaDataModel>Device action list in the scene.
nameStringScene name.
sceneIdStringScene ID.

QuecMetaDataModel Definition

FieldTypeDescription
actionListNSArray<QuecSceneActionModel *> *Device action list.
deviceKeyStringDeviceKey.
productKeyStringProductKey.
deviceNameStringDevice name.
logoImageStringDevice icon.
deviceTypeintDevice type.
1 Default normal device
2 Group

QuecSceneActionModel Definition

FieldTypeDescription
idintTSL feature ID.
codeStringTSL feature code.
dataTypeStringTSL data type.
actionIdintAction ID.
nameStringTSL feature name.
subNameStringData type of the TSL feature.
typeStringTSL feature type.
subTypeStringRead/Write mode of the TSL feature.

Add Scene

API

Add a new scene.

kotlin
fun addScene(sceneModel: QuecSceneModel, callback: QuecCallback<Unit>)

Parameter

ParameterRequiredDescription
sceneModelYScene property.
callbackYCallback function of the request.

Example

kotlin
val model = QuecSceneModel()
val sceneInfoModel = QuecSceneInfoModel()
val metaDataModel = QuecMetaDataModel()
val actionModel = QuecSceneActionModel()

model.isIsCommon = true
sceneInfoModel.name = "Turn on the device light"
sceneInfoModel.icon = "https://xxx/xxx.png"

actionModel.code = "switch"
actionModel.dataType = "BOOL"
actionModel.id = 1
actionModel.name = "Switch"
actionModel.subName = "Turn on the light"
actionModel.subType = "RW"
actionModel.type = "PROPERTY"
actionModel.value = true

metaDataModel.productKey = "pk"
metaDataModel.deviceKey = "dk"
metaDataModel.deviceType = 1

model.sceneInfo = sceneInfoModel
sceneInfoModel.metaDataList = listOf(metaDataModel)
metaDataModel.actionList = listOf(actionModel)

QuecSceneService.addScene(model) {
    if (it.isSuccess) {
        //Add a scene successfully.
    } else {
        //Failed to add a scene.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Edit Scene

API

Edit scene information.

kotlin
fun editScene(sceneModel: QuecSceneModel, callback: QuecCallback<Unit>)

Parameter

ParameterRequiredDescription
sceneModelYScene property.
callbackYCallback function of the request.

Example

kotlin
val model = QuecSceneModel() //Get the object from the scene list.
model.sceneInfo.name = "New name"
QuecSceneService.editScene(model) {
    if (it.isSuccess) {
        //Edit the scene successfully.
    } else {
        //Failed to edit the scene.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Delete Scene

API

Delete the specified scene.

kotlin
fun deleteScene(sceneId: String, callback: QuecCallback<Unit>)

Parameter

ParameterRequiredDescription
sceneIdYScene ID.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.deleteScene("sceneId") {
    if (it.isSuccess) {
        //Delete a scene successfully.
    } else {
        //Failed to delete a scene.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Get Scene Details

API

Get details of the specified scene.

kotlin
fun getSceneInfo(sceneId: String, callback: QuecCallback<QuecSceneModel>)

Parameter

ParameterRequiredDescription
sceneIdYScene ID.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.getSceneInfo("sceneId") {
    if (it.isSuccess) {
        //Get scene details successfully.
    } else {
        //Failed to get scene details.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Execute Scene

Execute Scene

API

Execute the specified scene.

kotlin
fun executeScene(sceneId: String, callback: QuecCallback<QuecActionExecuteResultModel>)

Parameter

ParameterRequiredDescription
sceneIdYScene ID.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.executeScene("sceneId") {
    if (it.isSuccess) {
        //Execute a scene successfully.
    } else {
        //Failed to execute a scanario.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

QuecActionExecuteResultModel Definition

FieldTypeDescription
executeResultbooleanExecution result.
failActionListList<QuecFailActionModel>List of failed executions.
failCountintThe number of failed executions.
successCountintThe number of successful executions.

QuecFailActionModelModel Definition

FieldTypeDescription
productKeyStringProductKey.
deviceKeyStringDeviceKey.
deviceNameStringDevice name.
imageLogoStringDevice logo.
reasonStringReason.

Test Scene

API

Test the execution of the scene configuration. A configuration can be executed even though the scene has not been saved to the platform.

kotlin
fun executeTestScene(sceneInfoModel: QuecSceneModel, callback: QuecCallback<QuecActionExecuteResultModel>)

Parameter

ParameterRequiredDescription
sceneModelYScene property.
callbackYCallback function of the request.

Example

kotlin
val model = QuecSceneModel() //Get the object from the scene list.
QuecSceneService.executeTestScene(model) {
    if (it.isSuccess) {
        //Test the execution of the scene configuration successfully.
    } else {
        //Failed to test the execution of the scene configuration.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Common Scene

Get Common Scene List

API

Get the list of common scenes.

kotlin
fun getCommonSceneList(pageNumber: Int, pageSize: Int, callback: QuecCallback<QuecPageResponse<QuecSceneModel>>)

Parameter

ParameterRequiredDescription
pageNumberYPage number.
pageSizeYPage size.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.getCommonSceneList(1, 10) {
    if (it.isSuccess) {
        //Get the list of common scenes successfully.
    } else {
        //Failed to get the list of common scenes.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Add Common Scenes in Batches

API

Add common scenes in batches.

kotlin
fun batchAddCommonScene(sceneIdList: List<String>, callback: QuecCallback<QuecAddCommonSceneIdModel>)

Parameter

ParameterRequiredDescription
sceneIdListYScene ID list.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.batchAddCommonScene(listOf("sceneId1", "sceneId2")) {
    if (it.isSuccess) {
        //Add common scenes in batches successfully.
    } else {
        //Failed to add common scenes in batches.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Delete Common Scenes in Batches

API

Delete common scenes in batches.

kotlin
fun batchDeleteCommonScene(sceneIdList: List<String>, callback: QuecCallback<QuecAddCommonSceneIdModel>)

Parameter

ParameterRequiredDescription
sceneIdListYScene ID list.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.batchDeleteCommonScene(listOf("sceneId1", "sceneId2")) {
    if (it.isSuccess) {
        //Delete common scenes in batches successfully.
    } else {
        //Failed to delete common scenes in batches.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Scene Logs

Get Scene Log List

API

Get scene log list.

kotlin
fun getSceneLogList(lastExecutionId: Long, limit: Int, callback: QuecCallback<List<QuecSceneLogItemModel>>)

Parameter

ParameterRequiredDescription
lastExecutionIdNID of the last execution log.
limitYThe number of the data to be queried.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.getSceneLogList(80, 10) {
    if (it.isSuccess) {
        //Get the scene log list successfully.
        val data = it.data //List data.
    } else {
        //Failed to get the scene log list.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

QuecSceneLogItemModel Definition

FieldTypeDescription
sceneIdStringScene ID.
sceneNameStringScene name.
sceneIconStringScene icon.
executionIdlongExecution ID.
executionTimelongExecution time.
executionResultintExecution result.
executionListList<QuecSceneLogExecutionModel>Execution result list.

QuecSceneLogExecutionModel Definition

FieldTypeDescription
productKeyStringProductKey.
deviceKeyStringDeviceKey.
deviceNameStringDevice name.
logoImageStringDevice logo.
executionResultStringExecution result.
actionResultListList<QuecSceneLogActionModel>Scene ID.

QuecSceneLogActionModel Definition

FieldTypeDescription
resultbooleanExecution result.
reasonStringReason.
createTimeStringTimestamps.
actionQuecSceneActionModelTSL model.

Get Scene Log Details

API

Get details of scene logs.

kotlin
fun getSceneLogDetailInfo(executionId: Long, callback: QuecCallback<QuecSceneLogItemModel>)

Parameter

ParameterRequiredDescription
executionIdYScene log ID.
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.getSceneLogDetailInfo(1000) {
    if (it.isSuccess) {
        //Get details of scene logs succesfully.
        val data = it.data //Detailed data.
    } else {
        //Failed to get details of scene logs.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}

Delete Scene Logs

API

Delete scene logs.

kotlin
fun clearSceneLog(callback: QuecCallback<Unit>)

Parameter

ParameterRequiredDescription
callbackYCallback function of the request.

Example

kotlin
QuecSceneService.clearSceneLog() {
    if (it.isSuccess) {
        //Delete scene logs successfully.
    } else {
        //Failed to delete scene logs.
        val code = it.code  //Error code.
        val msg = it.msg    //Error message.
    }
}