Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0b0f33b1e | |||
| a05373e50c | |||
| df5fb556a0 | |||
| 6a25b6acc7 | |||
| 25ba002da2 |
@@ -120,7 +120,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 +131,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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新设备版本信息
|
// 更新设备版本信息
|
||||||
|
|||||||
33
pkg/rpc/holiday.go
Normal file
33
pkg/rpc/holiday.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 节假日相关RPC
|
||||||
|
type Holiday struct{}
|
||||||
|
|
||||||
|
// 判断某个日期是否是节假日
|
||||||
|
func (h *Holiday) IsHoliday(date time.Time) (*bool, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"date": date.Format(time.DateOnly),
|
||||||
|
}
|
||||||
|
result := &Result[bool]{}
|
||||||
|
if err := GetRequest().Send("holiday.is_holiday", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var holiday *Holiday
|
||||||
|
|
||||||
|
func GetHoliday() *Holiday {
|
||||||
|
if holiday == nil {
|
||||||
|
holiday = &Holiday{}
|
||||||
|
}
|
||||||
|
return holiday
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
31
pkg/rpc/system.go
Normal file
31
pkg/rpc/system.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// 系统相关RPC
|
||||||
|
type System struct{}
|
||||||
|
|
||||||
|
// 获取系统位置
|
||||||
|
func (s *System) GetSystemLocation() (*SystemLocation, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"key": "system_location",
|
||||||
|
}
|
||||||
|
result := &Result[SystemLocation]{}
|
||||||
|
if err := GetRequest().Send("system.get_config", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var system *System
|
||||||
|
|
||||||
|
// 获取系统相关RPC
|
||||||
|
func GetSystem() *System {
|
||||||
|
if system == nil {
|
||||||
|
system = &System{}
|
||||||
|
}
|
||||||
|
return system
|
||||||
|
}
|
||||||
@@ -127,7 +127,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"` // 类型
|
||||||
@@ -148,8 +147,24 @@ type AutomationTask struct {
|
|||||||
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,omitempty"` // 自定义重复范围
|
CustomRepeatRange []uint8 `json:"custom_repeat_range"` // 自定义重复范围
|
||||||
IsSatisfyAll uint8 `json:"is_satisfy_all"` // 是否要满足所有条件
|
IsSatisfyAll uint8 `json:"is_satisfy_all"` // 是否要满足所有条件
|
||||||
ConditionList []AutomationCondition `json:"condition_list"` // 条件列表
|
EventConditionList []AutomationCondition `json:"event_condition_list"` // 事件条件列表
|
||||||
|
StatusConditionList []AutomationCondition `json:"status_condition_list"` // 事件条件列表
|
||||||
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 系统位置
|
||||||
|
type SystemLocation struct {
|
||||||
|
Longitude float64 `json:"longitude,string"` // 经度
|
||||||
|
Latitude float64 `json:"latitude,string"` // 维度
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户详情
|
||||||
|
type UserDetail struct {
|
||||||
|
Mobile *string `json:"mobile,omitempty"` // 手机号
|
||||||
|
Email *string `json:"email,omitempty"` // 邮箱
|
||||||
|
Nickname *string `json:"nickname,omitempty"` // 昵称
|
||||||
|
QQ *string `json:"qq,omitempty"` // QQ
|
||||||
|
Status uint8 `json:"status"` // 状态
|
||||||
|
}
|
||||||
|
|||||||
62
pkg/rpc/user.go
Normal file
62
pkg/rpc/user.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// 用户相关RPC
|
||||||
|
type User struct{}
|
||||||
|
|
||||||
|
// 获取用户详情
|
||||||
|
func (u *User) GetDetail(userId uint32) (*UserDetail, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"user_id": userId,
|
||||||
|
"field_list": []string{"mobile", "email", "nickname", "qq", "status"},
|
||||||
|
}
|
||||||
|
result := &Result[UserDetail]{}
|
||||||
|
if err := GetRequest().Send("user.get_detail", 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) 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
|
||||||
|
|
||||||
|
// 获取用户相关RPC
|
||||||
|
func GetUser() *User {
|
||||||
|
if user == nil {
|
||||||
|
user = &User{}
|
||||||
|
}
|
||||||
|
return user
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user