@quec-wx-mp/api-auto
v1.0.0
Published
小程序插件 自动化
Readme
自动化
自动化模块,提供自动化配置查询、创建、编辑、删除、启停、测试和日志管理等 API。
安装
npm install @quec-wx-mp/api-autoimport auto from '@quec-wx-mp/api-auto'
const plugin = requirePlugin('quecPlugin')
plugin.use(auto)API 列表
| 方法 | 说明 | | ----------------- | -------------------- | | autoPublish | 获取自动化物模型配置 | | autoSave | 创建自动化 | | autoEdit | 编辑自动化 | | autoDel | 删除自动化 | | autoDetail | 查询自动化详情 | | autoList | 查询自动化列表 | | autoStatus | 启停自动化 | | autoTest | 测试自动化 | | getTestAutomation | 查询自动化测试结果 | | autoLogList | 查询自动化日志列表 | | autoLogDetail | 查询自动化日志详情 | | autoClear | 清除自动化日志 |
API 详细说明
1) 获取自动化物模型配置
接口名称
autoPublish功能描述
获取自动化联动配置(条件/动作物模型配置)。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ---------- | -------- | ------ | ---- | ---------------------------------- | | productKey | string | - | 是 | 产品 ProductKey | | type | number | 0 | 否 | 查询类型(0 全部,1 条件,2 动作) | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为自动化物模型配置。
示例代码
plugin.auto.autoPublish({
productKey: 'product_key',
type: 0,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})2) 创建自动化
接口名称
autoSave功能描述
创建自动化规则。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------- | -------- | ------ | ---- | ---------------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | conditionType | number | - | 是 | 触发类型(1 满足任意,2 满足所有) | | icon | string | '' | 是 | 自动化图标 | | name | string | - | 是 | 自动化名称 | | nameType | number | - | 是 | 名称类型(1 默认生成,2 用户填写) | | conditions | array | - | 是 | 触发条件数组 | | actions | array | - | 是 | 执行动作数组 | | precondition | object | - | 否 | 生效时间条件 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为创建结果。
示例代码
plugin.auto.autoSave({
fid: 'family_id',
conditionType: 1,
icon: 'auto_icon',
name: '自动化示例',
nameType: 2,
conditions: [
{
type: 1,
timer: {
type: 1,
time: '08:00',
timeZone: 'GMT+08:00'
},
sort: 1
}
],
actions: [
{
type: 2,
productKey: 'product_key',
deviceKey: 'device_key',
sort: 1,
property: {
id: 1,
code: 'switch',
name: '开关',
dataType: 'BOOL',
value: true
}
}
],
precondition: {
effectDateType: 0,
effectTimeType: 2,
timeZone: 'GMT+08:00'
},
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})3) 编辑自动化
接口名称
autoEdit功能描述
编辑已有自动化规则。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------- | -------- | ------ | ---- | ---------------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | automationId | number | - | 是 | 自动化 ID | | conditionType | number | - | 是 | 触发类型(1 满足任意,2 满足所有) | | icon | string | - | 是 | 自动化图标 | | name | string | - | 是 | 自动化名称 | | nameType | number | - | 是 | 名称类型(1 默认生成,2 用户填写) | | conditions | array | - | 是 | 触发条件数组 | | actions | array | - | 是 | 执行动作数组 | | precondition | object | - | 否 | 生效时间条件 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为编辑结果。
示例代码
plugin.auto.autoEdit({
fid: 'family_id',
automationId: 1001,
conditionType: 2,
icon: 'auto_icon',
name: '离家自动化',
nameType: 2,
conditions: [],
actions: [],
precondition: {},
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})4) 删除自动化
接口名称
autoDel功能描述
根据 automationId 删除自动化。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------ | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | automationId | number | - | 是 | 自动化 ID | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.auto.autoDel({
fid: 'family_id',
automationId: 1001,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})5) 查询自动化详情
接口名称
autoDetail功能描述
根据 automationId 查询自动化详情。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------ | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | automationId | number | - | 是 | 自动化 ID | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为自动化详情。
示例代码
plugin.auto.autoDetail({
fid: 'family_id',
automationId: 1001,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})6) 查询自动化列表
接口名称
autoList功能描述
分页查询自动化列表。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | page | number | 1 | 是 | 页码 | | pageSize | number | 10 | 是 | 每页条数 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为自动化分页列表。
示例代码
plugin.auto.autoList({
fid: 'family_id',
page: 1,
pageSize: 10,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})7) 启停自动化
接口名称
autoStatus功能描述
开启或关闭自动化。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------ | -------- | ------ | ---- | --------------------------------- | | automationId | number | - | 是 | 自动化 ID | | status | boolean | - | 是 | 启停状态(true 启用,false 停用) | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.auto.autoStatus({
automationId: 1001,
status: true,
fid: 'family_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})8) 测试自动化
接口名称
autoTest功能描述
测试自动化动作执行。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | timeout | number | 120 | 否 | 测试超时时间(秒) | | actions | array | - | 是 | 执行动作数组 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data通常包含 testResultId。
示例代码
plugin.auto.autoTest({
fid: 'family_id',
timeout: 120,
actions: [
{
type: 2,
productKey: 'product_key',
deviceKey: 'device_key',
sort: 1,
property: {
id: 1,
code: 'switch',
name: '开关',
dataType: 'BOOL',
value: true
}
}
],
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})9) 查询自动化测试结果
接口名称
getTestAutomation功能描述
根据 testResultId 轮询获取自动化测试结果。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------ | -------- | ------ | ---- | ----------------- | | testResultId | string | - | 是 | 自动化测试结果 ID | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为测试结果状态。
示例代码
plugin.auto.getTestAutomation({
testResultId: 'test_result_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})10) 查询自动化日志列表
接口名称
autoLogList功能描述
分页查询自动化日志列表。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | --------- | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | lastLogId | string | - | 是 | 分页最后一条日志 ID | | limit | number | 10 | 是 | 每页条数 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为日志列表。
示例代码
plugin.auto.autoLogList({
fid: 'family_id',
lastLogId: '1000',
limit: 10,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})11) 查询自动化日志详情
接口名称
autoLogDetail功能描述
根据日志 ID 查询自动化日志详情。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | logId | string | - | 是 | 日志 ID | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为日志详情。
示例代码
plugin.auto.autoLogDetail({
fid: 'family_id',
logId: '1001',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})12) 清除自动化日志
接口名称
autoClear功能描述
清除自动化日志。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------------------------- | | fid | string | - | 否 | 家庭 ID,开启家居模式时传入 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.auto.autoClear({
fid: 'family_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})