@quec-wx-mp/api-scene
v1.0.0
Published
小程序插件 智能场景
Readme
智能场景
智能场景模块,提供场景查询、创建、编辑、执行、测试和日志管理等 API。
安装
npm install @quec-wx-mp/api-sceneimport scene from '@quec-wx-mp/api-scene'
const plugin = requirePlugin('quecPlugin')
plugin.use(scene)API 列表
| 方法 | 说明 | | ---------------------- | ---------------- | | selectCommonSceneList | 查询常用场景列表 | | selectSceneDetail | 查询场景详情 | | selectSceneList | 查询场景列表 | | batchAddCommonScene | 批量添加常用场景 | | batchDeleteCommonScene | 批量移除常用场景 | | deleteSceneLog | 删除场景日志 | | sceneCreate | 创建场景 | | sceneDelete | 删除场景 | | sceneEdit | 编辑场景 | | sceneExecute | 执行场景 | | sceneTest | 测试场景 | | selectSceneLogDetail | 查询场景日志详情 | | selectSceneLogList | 查询场景日志列表 |
API 详细说明
1) 查询常用场景列表
接口名称
selectCommonSceneList功能描述
查询常用场景列表。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | page | number | - | 是 | 当前页 | | pageSize | string | - | 是 | 页大小 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.code为状态码,res.data为常用场景列表数据。
示例代码
plugin.scene.selectCommonSceneList({
fid: 'family_id',
page: 1,
pageSize: '10',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})2) 查询场景详情
接口名称
selectSceneDetail功能描述
根据场景 id 查询场景详情。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | sceneId | string | - | 否 | 场景 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为场景详情。
示例代码
plugin.scene.selectSceneDetail({
fid: 'family_id',
sceneId: 'scene_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})3) 查询场景列表
接口名称
selectSceneList功能描述
分页查询场景列表,支持按场景名称筛选。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | --------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | page | number | - | 是 | 当前页 | | pageSize | string | - | 是 | 页大小 | | sceneName | string | - | 否 | 场景名称 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为场景分页列表。
示例代码
plugin.scene.selectSceneList({
fid: 'family_id',
page: 1,
pageSize: '10',
sceneName: '回家模式',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})4) 批量添加常用场景
接口名称
batchAddCommonScene功能描述
将多个场景批量添加到常用场景。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ----------- | -------- | ------ | ---- | ------------ | | fid | string | - | 是 | 家庭 id | | sceneIdList | string[] | - | 是 | 场景 id 列表 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.scene.batchAddCommonScene({
fid: 'family_id',
sceneIdList: ['scene_1', 'scene_2'],
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})5) 批量移除常用场景
接口名称
batchDeleteCommonScene功能描述
将多个场景从常用场景中批量移除。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ----------- | -------- | ------ | ---- | ------------ | | fid | string | - | 是 | 家庭 id | | sceneIdList | string[] | - | 是 | 场景 id 列表 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.scene.batchDeleteCommonScene({
fid: 'family_id',
sceneIdList: ['scene_1', 'scene_2'],
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})6) 删除场景日志
接口名称
deleteSceneLog功能描述
删除当前用户下的场景日志。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 是 | 家庭 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.scene.deleteSceneLog({
fid: 'family_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})7) 创建场景
接口名称
sceneCreate功能描述
创建场景。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | --------------------- | ------ | ---- | ------------ | | arr | SceneCreationConfig[] | - | 是 | 场景配置数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为创建结果。
示例代码
plugin.scene.sceneCreate({
arr: [
{
fid: 'family_id',
isCommon: false,
sceneInfo: {
icon: 'scene_icon',
id: 1,
name: '回家模式',
sceneId: '',
metaDataList: [
{
deviceKey: 'device_key',
deviceName: '客厅灯',
logoImage: 'logo.png',
productKey: 'product_key',
actionList: [
{
actionId: 1,
code: 'switch',
dataType: 'BOOL',
id: 1,
name: '开关',
subName: '',
subType: '',
type: 'WRITE-ATTR',
unit: '',
value: true
}
]
}
]
}
}
],
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})8) 删除场景
接口名称
sceneDelete功能描述
根据场景 id 删除场景。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | sceneId | string | - | 否 | 场景 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.scene.sceneDelete({
fid: 'family_id',
sceneId: 'scene_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})9) 编辑场景
接口名称
sceneEdit功能描述
编辑场景,入参结构与创建场景一致。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | --------------------- | ------ | ---- | ------------ | | arr | SceneCreationConfig[] | - | 是 | 场景配置数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为编辑结果。
示例代码
plugin.scene.sceneEdit({
arr: [
{
fid: 'family_id',
isCommon: true,
sceneInfo: {
icon: 'scene_icon',
id: 1,
name: '离家模式',
sceneId: 'scene_id',
metaDataList: [
{
deviceKey: 'device_key',
deviceName: '空调',
logoImage: 'logo.png',
productKey: 'product_key',
actionList: [
{
actionId: 2,
code: 'power',
dataType: 'BOOL',
id: 2,
name: '电源',
subName: '',
subType: '',
type: 'WRITE-ATTR',
unit: '',
value: false
}
]
}
]
}
}
],
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})10) 执行场景
接口名称
sceneExecute功能描述
执行指定场景。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 否 | 家庭 id | | sceneId | string | - | 否 | 场景 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为执行结果。
示例代码
plugin.scene.sceneExecute({
fid: 'family_id',
sceneId: 'scene_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})11) 测试场景
接口名称
sceneTest功能描述
测试场景配置,入参结构与创建场景一致。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | --------------------- | ------ | ---- | ------------ | | arr | SceneCreationConfig[] | - | 是 | 场景配置数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为测试结果。
示例代码
plugin.scene.sceneTest({
arr: [
{
fid: 'family_id',
isCommon: false,
sceneInfo: {
icon: 'scene_icon',
id: 1,
name: '测试场景',
sceneId: '',
metaDataList: [
{
deviceKey: 'device_key',
deviceName: '插座',
logoImage: 'logo.png',
productKey: 'product_key',
actionList: [
{
actionId: 3,
code: 'switch',
dataType: 'BOOL',
id: 3,
name: '开关',
subName: '',
subType: '',
type: 'WRITE-ATTR',
unit: '',
value: true
}
]
}
]
}
}
],
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})12) 查询场景日志详情
接口名称
selectSceneLogDetail功能描述
根据 executionId 查询场景日志详情。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ----------- | -------- | ------ | ---- | ----------- | | executionId | number | - | 否 | 执行日志 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为日志详情。
示例代码
plugin.scene.selectSceneLogDetail({
executionId: 1001,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})13) 查询场景日志列表
接口名称
selectSceneLogList功能描述
查询当前用户下的场景日志列表。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | --------------- | -------- | ------ | ---- | ---------------------------- | | fid | string | - | 否 | 家庭 id | | lastExecutionId | number | - | 否 | 上一次 executionId,用于翻页 | | limit | number | - | 否 | 限制返回数量 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为日志列表。
示例代码
plugin.scene.selectSceneLogList({
fid: 'family_id',
lastExecutionId: 1001,
limit: 10,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})