Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 55638aee29 | |||
| 84655ceebd | |||
| 0f0795944c | |||
| ad24dd7335 | |||
| 1f8e253f69 | |||
| a0b0f33b1e | |||
| a05373e50c | |||
| df5fb556a0 |
@@ -8,6 +8,22 @@ import (
|
|||||||
// 设备相关RPC
|
// 设备相关RPC
|
||||||
type Device struct{}
|
type Device struct{}
|
||||||
|
|
||||||
|
// 获取设备类型详情
|
||||||
|
func (d *Device) GetTypeDetail(deviceTypeId uint32) (*DeviceTypeDetail, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"device_type_id": deviceTypeId,
|
||||||
|
"field_list": []string{},
|
||||||
|
}
|
||||||
|
result := &Result[DeviceTypeDetail]{}
|
||||||
|
if err := GetRequest().Send("device.get_type_detail", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 获取设备详情
|
// 获取设备详情
|
||||||
func (d *Device) GetDetail(deviceId uint32) (*DeviceDetail, error) {
|
func (d *Device) GetDetail(deviceId uint32) (*DeviceDetail, error) {
|
||||||
body := map[string]any{
|
body := map[string]any{
|
||||||
@@ -120,7 +136,7 @@ func (d *Device) SetAttribute(deviceId uint32, attributeSet map[string]any) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取设备属性
|
// 获取设备属性
|
||||||
func (d *Device) GetAttribute(deviceId uint32) (*map[string]any, error) {
|
func (d *Device) GetAttribute(deviceId uint32) (map[string]any, error) {
|
||||||
body := map[string]any{
|
body := map[string]any{
|
||||||
"device_id": deviceId,
|
"device_id": deviceId,
|
||||||
}
|
}
|
||||||
@@ -131,7 +147,7 @@ func (d *Device) GetAttribute(deviceId uint32) (*map[string]any, error) {
|
|||||||
if result.Code != 0 {
|
if result.Code != 0 {
|
||||||
return nil, fmt.Errorf("%s", result.Message)
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
}
|
}
|
||||||
return &result.Data, nil
|
return result.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新设备版本信息
|
// 更新设备版本信息
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package rpc
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// 服务相关RPC
|
|
||||||
type Server struct{}
|
|
||||||
|
|
||||||
// 获取Websocket签名信息
|
|
||||||
func (s *Server) GetWebsocketSignData(sign string) (*WebsocketSignData, error) {
|
|
||||||
body := map[string]any{
|
|
||||||
"sign": sign,
|
|
||||||
}
|
|
||||||
result := &Result[WebsocketSignData]{}
|
|
||||||
if err := GetRequest().Send("server.get_websocket_sign", body, result); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if result.Code != 0 {
|
|
||||||
return nil, fmt.Errorf("%s", result.Message)
|
|
||||||
}
|
|
||||||
return &result.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除Websocket签名
|
|
||||||
func (s *Server) DeleteWebsocketSign(sign string) error {
|
|
||||||
body := map[string]any{
|
|
||||||
"sign": sign,
|
|
||||||
}
|
|
||||||
result := &Result[WebsocketSignData]{}
|
|
||||||
if err := GetRequest().Send("server.get_websocket_sign", body, result); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if result.Code != 0 {
|
|
||||||
return fmt.Errorf("%s", result.Message)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var server *Server
|
|
||||||
|
|
||||||
// 获取服务相关RPC类
|
|
||||||
func GetServer() *Server {
|
|
||||||
if server == nil {
|
|
||||||
server = &Server{}
|
|
||||||
}
|
|
||||||
return server
|
|
||||||
}
|
|
||||||
@@ -42,6 +42,19 @@ type Result[D any] struct {
|
|||||||
Data D `json:"data"` // 数据
|
Data D `json:"data"` // 数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设备类型详情
|
||||||
|
type DeviceTypeDetail struct {
|
||||||
|
Id uint32 `json:"id"` // ID
|
||||||
|
Name string `json:"name"` // 名称
|
||||||
|
Img string `json:"img"` // 图片地址
|
||||||
|
ConnectType uint8 `json:"connect_type"` // 连接类型
|
||||||
|
AppMaxSize uint32 `json:"app_max_size"` // 应用包最大大小
|
||||||
|
HeartbeatCheckInterval uint32 `json:"heartbeat_check_interval"` // 心跳检测间隔
|
||||||
|
HeartbeatIdleTime uint32 `json:"heartbeat_idle_time"` // 心跳最大空闲时间
|
||||||
|
AllowOnlineUpgrade uint8 `json:"allow_online_upgrade"` // 是否允许在线升级
|
||||||
|
AllowVoiceAssistant uint8 `json:"allow_voice_assistant"` // 是否允许使用语言助手
|
||||||
|
}
|
||||||
|
|
||||||
// 设备详情
|
// 设备详情
|
||||||
type DeviceDetail struct {
|
type DeviceDetail struct {
|
||||||
Type uint8 `json:"type"` // 设备类型
|
Type uint8 `json:"type"` // 设备类型
|
||||||
@@ -61,7 +74,7 @@ type DeviceAttributeOption struct {
|
|||||||
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 *map[uint8]string `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"` // 设备属性列表
|
||||||
@@ -127,7 +140,6 @@ type AutomationCondition struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 自动化动作
|
// 自动化动作
|
||||||
|
|
||||||
type AutomationAction struct {
|
type AutomationAction struct {
|
||||||
Id uint32 `json:"id"` // ID
|
Id uint32 `json:"id"` // ID
|
||||||
Type uint8 `json:"type"` // 类型
|
Type uint8 `json:"type"` // 类型
|
||||||
@@ -143,14 +155,16 @@ type AutomationAction struct {
|
|||||||
type AutomationTask struct {
|
type AutomationTask struct {
|
||||||
Id uint32 `json:"id"` // ID
|
Id uint32 `json:"id"` // ID
|
||||||
Title string `json:"title"` // 标题
|
Title string `json:"title"` // 标题
|
||||||
CreateUserId uint32 `json:"create_user_id"` // 创建用户ID
|
FamilyId uint32 `json:"family_id"` // 家庭ID
|
||||||
EffectivePeriod uint8 `json:"effective_period"` // 生效时段
|
EffectivePeriod uint8 `json:"effective_period"` // 生效时段
|
||||||
PeriodBeginTime *string `json:"period_begin_time,omitempty"` // 时段开始时间
|
PeriodBeginTime *string `json:"period_begin_time,omitempty"` // 时段开始时间
|
||||||
PeriodEndTime *string `json:"period_end_time,omitempty"` // 时段结束时间
|
PeriodEndTime *string `json:"period_end_time,omitempty"` // 时段结束时间
|
||||||
RepeatType uint8 `json:"repeat_type"` // 重复类型
|
RepeatType uint8 `json:"repeat_type"` // 重复类型
|
||||||
CustomRepeatRange []uint8 `json:"custom_repeat_range"` // 自定义重复范围
|
CustomRepeatRange []uint8 `json:"custom_repeat_range"` // 自定义重复范围
|
||||||
IsSatisfyAll uint8 `json:"is_satisfy_all"` // 是否要满足所有条件
|
IsSatisfyAll uint8 `json:"is_satisfy_all"` // 是否要满足所有条件
|
||||||
ConditionList []AutomationCondition `json:"condition_list"` // 条件列表
|
Status uint8 `json:"status"` // 状态
|
||||||
|
EventConditionList []AutomationCondition `json:"event_condition_list"` // 事件条件列表
|
||||||
|
StatusConditionList []AutomationCondition `json:"status_condition_list"` // 事件条件列表
|
||||||
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,3 +182,12 @@ type UserDetail struct {
|
|||||||
QQ *string `json:"qq,omitempty"` // QQ
|
QQ *string `json:"qq,omitempty"` // QQ
|
||||||
Status uint8 `json:"status"` // 状态
|
Status uint8 `json:"status"` // 状态
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 家庭详情
|
||||||
|
type UserFamilyDetail struct {
|
||||||
|
Name string `json:"name"` // 名称
|
||||||
|
Latitude *float64 `json:"latitude,omitempty"` //纬度
|
||||||
|
Longitude *float64 `json:"longitude,omitempty"` // 经度
|
||||||
|
Address *string `json:"address,omitempty"` // 地址
|
||||||
|
CityAdCode *string `json:"city_ad_code,omitempty"` // 城市地理编码
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,36 @@ func (u *User) GetDetail(userId uint32) (*UserDetail, error) {
|
|||||||
return &result.Data, nil
|
return &result.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取Websocket签名信息
|
||||||
|
func (s *User) GetWebsocketSignData(sign string) (*WebsocketSignData, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"sign": sign,
|
||||||
|
}
|
||||||
|
result := &Result[WebsocketSignData]{}
|
||||||
|
if err := GetRequest().Send("user.get_websocket_sign", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除Websocket签名
|
||||||
|
func (s *User) DeleteWebsocketSign(sign string) error {
|
||||||
|
body := map[string]any{
|
||||||
|
"sign": sign,
|
||||||
|
}
|
||||||
|
result := &Result[WebsocketSignData]{}
|
||||||
|
if err := GetRequest().Send("user.get_websocket_sign", body, result); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var user *User
|
var user *User
|
||||||
|
|
||||||
// 获取用户相关RPC
|
// 获取用户相关RPC
|
||||||
|
|||||||
48
pkg/rpc/user_family.go
Normal file
48
pkg/rpc/user_family.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// 用户家庭相关RPC
|
||||||
|
type UserFamily struct{}
|
||||||
|
|
||||||
|
// 获取家庭详情
|
||||||
|
func (uf *UserFamily) GetDetail(familyId uint32) (*UserFamilyDetail, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"family_id": familyId,
|
||||||
|
"field_list": []string{"name", "latitude", "longitude", "address", "city_ad_code"},
|
||||||
|
}
|
||||||
|
result := &Result[UserFamilyDetail]{}
|
||||||
|
if err := GetRequest().Send("user_family.get_detail", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送通知
|
||||||
|
func (uf *UserFamily) SendNotice(familyId uint32, content string) error {
|
||||||
|
body := map[string]any{
|
||||||
|
"family_id": familyId,
|
||||||
|
"content": content,
|
||||||
|
}
|
||||||
|
result := &Result[any]{}
|
||||||
|
if err := GetRequest().Send("user_family.send_notice", body, result); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var userFamily *UserFamily
|
||||||
|
|
||||||
|
// 获取用户相关RPC
|
||||||
|
func GetUserFamily() *UserFamily {
|
||||||
|
if userFamily == nil {
|
||||||
|
userFamily = &UserFamily{}
|
||||||
|
}
|
||||||
|
return userFamily
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user