添加自动化相关方法
This commit is contained in:
52
pkg/rpc/automation.go
Normal file
52
pkg/rpc/automation.go
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 自动化相关RPC
|
||||||
|
type Automation struct{}
|
||||||
|
|
||||||
|
// 获取自动化列表
|
||||||
|
func (a *Automation) GetList() (*[]AutomationTask, error) {
|
||||||
|
result := &Result[[]AutomationTask]{}
|
||||||
|
if err := GetRequest().Send("automation.list", map[string]any{}, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取自动化详情
|
||||||
|
func (a *Automation) GetDetail(automationId uint32) (*AutomationTask, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"automation_id": automationId,
|
||||||
|
}
|
||||||
|
result := &Result[AutomationTask]{}
|
||||||
|
if err := GetRequest().Send("automation.detail", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新条件最后执行时间
|
||||||
|
func (a *Automation) UpdateConditionLastExecuteTime(conditionId uint32, lastExecuteTime time.Time) error {
|
||||||
|
body := map[string]any{
|
||||||
|
"condition_id": conditionId,
|
||||||
|
"time": lastExecuteTime.Format(time.DateTime),
|
||||||
|
}
|
||||||
|
result := &Result[any]{}
|
||||||
|
if err := GetRequest().Send("automation.update_condition_last_execute_time", body, result); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -37,49 +37,49 @@ const (
|
|||||||
|
|
||||||
// 响应结果
|
// 响应结果
|
||||||
type Result[D any] struct {
|
type Result[D any] struct {
|
||||||
Code ResultCode `json:"code"`
|
Code ResultCode `json:"code"` // 状态码
|
||||||
Message string `json:"message"`
|
Message string `json:"message"` // 消息
|
||||||
Data D `json:"data"`
|
Data D `json:"data"` // 数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设备详情
|
// 设备详情
|
||||||
type DeviceDetail struct {
|
type DeviceDetail struct {
|
||||||
Type uint8 `json:"type"`
|
Type uint8 `json:"type"` // 设备类型
|
||||||
ConnectType uint8 `json:"connect_type"`
|
ConnectType uint8 `json:"connect_type"` // 连接类型
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"` // 秘钥
|
||||||
PId uint32 `json:"p_id"`
|
PId uint32 `json:"p_id"` // 上层设备ID
|
||||||
DataId uint32 `json:"data_id"`
|
DataId uint32 `json:"data_id"` // 参数数据ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设备属性参数
|
// 设备属性参数
|
||||||
type DeviceAttributeOption struct {
|
type DeviceAttributeOption struct {
|
||||||
Type uint8 `json:"type"`
|
Type uint8 `json:"type"` // 设备类型
|
||||||
ContentType uint8 `json:"content_type"`
|
ConnectType uint8 `json:"connect_type"` // 连接类型
|
||||||
Attribute []struct {
|
Attribute []struct {
|
||||||
Type uint8 `json:"type"`
|
Type uint8 `json:"type"` // 属性类型
|
||||||
Name string `json:"name"`
|
Name string `json:"name"` // 属性名称
|
||||||
Flag uint8 `json:"flag"`
|
Flag uint8 `json:"flag"` // 属性标识
|
||||||
Field string `json:"field"`
|
Field string `json:"field"` // 属性字段名
|
||||||
Readonly bool `json:"readonly"`
|
Readonly bool `json:"readonly"` // 是否只读
|
||||||
AllowItem *[]uint8 `json:"allow_item,omitempty"`
|
AllowItem *[]uint8 `json:"allow_item,omitempty"` // 可用选项列表
|
||||||
Min *uint32 `json:"min,omitempty"`
|
Min *uint32 `json:"min,omitempty"` // 最小值
|
||||||
Max *uint32 `json:"max,omitempty"`
|
Max *uint32 `json:"max,omitempty"` // 最大值
|
||||||
} `json:"attribute"`
|
} `json:"attribute"` // 设备属性列表
|
||||||
}
|
}
|
||||||
|
|
||||||
// Websocket签名数据
|
// Websocket签名数据
|
||||||
type WebsocketSignData struct {
|
type WebsocketSignData struct {
|
||||||
UserId uint32 `json:"user_id"`
|
UserId uint32 `json:"user_id"` // 用户ID
|
||||||
Platform string `json:"platform"`
|
Platform string `json:"platform"` // 平台
|
||||||
}
|
}
|
||||||
|
|
||||||
// 语音助手数据
|
// 语音助手数据
|
||||||
type VoiceAssistant struct {
|
type VoiceAssistant struct {
|
||||||
Id uint32 `json:"id"`
|
Id uint32 `json:"id"` // ID
|
||||||
Type uint8 `json:"type"`
|
Type uint8 `json:"type"` // 类型
|
||||||
OnlineStatus uint8 `json:"online_status"`
|
OnlineStatus uint8 `json:"online_status"` // 在线状态
|
||||||
BemFaEnable uint8 `json:"bem_fa_enable"`
|
BemFaEnable uint8 `json:"bem_fa_enable"` // 是否启用巴法平台
|
||||||
BemFaName string `json:"bem_fa_name"`
|
BemFaName string `json:"bem_fa_name"` // 巴法平台名称
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设备操作日志平台
|
// 设备操作日志平台
|
||||||
@@ -111,3 +111,45 @@ const (
|
|||||||
// 设备操作日志结果 - 失败
|
// 设备操作日志结果 - 失败
|
||||||
DeviceOperationLogResultFail
|
DeviceOperationLogResultFail
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 自动化条件
|
||||||
|
type AutomationCondition struct {
|
||||||
|
Id uint32 `json:"id"` // ID
|
||||||
|
ConditionType uint8 `json:"condition_type"` // 条件类型
|
||||||
|
TriggerType uint8 `json:"trigger_type"` // 触发类型
|
||||||
|
DeviceId *uint32 `json:"device_id,omitempty"` // 设备ID
|
||||||
|
DeviceAttribute *string `json:"device_attribute,omitempty"` // 设备属性
|
||||||
|
TargetValue *string `json:"target_value,omitempty"` // 目标值
|
||||||
|
TimeValue *string `json:"time_value,omitempty"` // 时间值
|
||||||
|
RepeatType *uint8 `json:"repeat_type,omitempty"` // 时间重复类型
|
||||||
|
CustomRepeatRange []uint8 `json:"custom_repeat_range"` // 自定义重复范围
|
||||||
|
LastExecuteTime *string `json:"last_execute_time,omitempty"` // 最后执行时间
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动化动作
|
||||||
|
|
||||||
|
type AutomationAction struct {
|
||||||
|
Id uint32 `json:"id"` // ID
|
||||||
|
Type uint8 `json:"type"` // 类型
|
||||||
|
DeviceId *uint32 `json:"device_id,omitempty"` // 设备ID
|
||||||
|
DeviceAttribute *string `json:"device_attribute,omitempty"` // 设备属性
|
||||||
|
TargetValue *string `json:"target_value,omitempty"` // 目标值
|
||||||
|
ValueType *uint8 `json:"value_type,omitempty"` // 值类型
|
||||||
|
DelayDuration *uint32 `json:"delay_duration,omitempty"` // 延时时长
|
||||||
|
NoticeContent *string `json:"notice_content,omitempty"` // 通知内容
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动化任务
|
||||||
|
type AutomationTask struct {
|
||||||
|
Id uint32 `json:"id"` // ID
|
||||||
|
Title string `json:"title"` // 标题
|
||||||
|
CreateUserId uint32 `json:"create_user_id"` // 创建用户ID
|
||||||
|
EffectivePeriod uint8 `json:"effective_period"` // 生效时段
|
||||||
|
PeriodBeginTime *string `json:"period_begin_time,omitempty"` // 时段开始时间
|
||||||
|
PeriodEndTime *string `json:"period_end_time,omitempty"` // 时段结束时间
|
||||||
|
RepeatType uint8 `json:"repeat_type"` // 重复类型
|
||||||
|
CustomRepeatRange *[]uint8 `json:"custom_repeat_range,omitempty"` // 自定义重复范围
|
||||||
|
IsSatisfyAll uint8 `json:"is_satisfy_all"` // 是否要满足所有条件
|
||||||
|
ConditionList []AutomationCondition `json:"condition_list"` // 条件列表
|
||||||
|
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user