scene

package
v0.10.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package scene 触发器

Package scene 执行动作

Package scene 执行动作

Package scene 触发条件

Index

Constants

View Source
const (
	StateKeepTypeDuration  = "duration"
	StateKeepTypeRepeating = "repeat" //todo
)
View Source
const (
	AlarmDealStatusWaring    = 1 //告警中
	AlarmDealStatusIgnore    = 2 //忽略
	AlarmDealStatusInHand    = 3 //正在处理
	AlarmDealStatusProcessed = 4 //已处理
)
View Source
const (
	NotifyUserAccount        NotifyUserType = "account"
	NotifyUserID                            = "userID"
	NotifyDeviceOwner                       = "deviceOwner"        //设备拥有人
	NotifyDeviceProjectAdmin                = "deviceProjectAdmin" //拥有设备项目权限的管理员
	NotifyDeviceAreaAdmin                   = "deviceAreaAdmin"    //拥有设备区域权限的管理员
	NotifyDeviceProjectAll                  = "deviceProjectAll"   //拥有设备项目权限的管理员
	NotifyDeviceAreaAll                     = "deviceAreaAll"      //拥有设备区域权限的管理员
)
View Source
const (
	WhenRangeTypeDate = "date"
	WhenRangeTypeTime = "time"
)
View Source
const (
	WeatherTypeTemp     = "temp"     //温度
	WeatherTypeHumidity = "humidity" //湿度
)

Variables

View Source
var RepeatTypeLen = map[string]int{
	RepeatTypeWeek:  7,
	RepeatTypeMount: 31,
}

Functions

func GetDeviceAlias

func GetDeviceAlias(ctx context.Context, cache dmExport.DeviceCacheT, productID string, deviceName string) string

func TermCompareAll

func TermCompareAll[dt constraints.Ordered](t CmpType, data dt, values []dt) bool

Types

type Action

type Action struct {
	ID     int64         `json:"id"`
	Order  int64         `json:"order"`
	Type   ActionType    `json:"type"`             //执行器类型 notify: 通知 delay:延迟  device:设备输出  alarm: 告警
	Delay  int64         `json:"delay,omitempty"`  //秒数
	Alarm  *ActionAlarm  `json:"alarm,omitempty"`  //告警
	Notify *ActionNotify `json:"notify,omitempty"` //消息通知
	Device *ActionDevice `json:"device,omitempty"`
	Scene  *ActionScene  `json:"scene,omitempty"`
}

func (*Action) Execute

func (a *Action) Execute(ctx context.Context, repo ActionRepo) error

执行操作

func (*Action) GetFlowInfo

func (a *Action) GetFlowInfo() (ret *FlowInfo)

func (*Action) Validate

func (a *Action) Validate(repo CheckRepo) error

type ActionAlarm

type ActionAlarm struct {
	Mode ActionAlarmMode `json:"mode,omitempty"` //告警模式  trigger: 触发告警  relieve: 解除告警
}

func (*ActionAlarm) Execute

func (a *ActionAlarm) Execute(ctx context.Context, repo ActionRepo) error

func (*ActionAlarm) Validate

func (a *ActionAlarm) Validate() error

type ActionAlarmMode

type ActionAlarmMode = string
const (
	ActionAlarmModeTrigger ActionAlarmMode = "trigger" //触发告警
	ActionAlarmModeRelieve ActionAlarmMode = "relieve" //接触告警
)

type ActionDevice

type ActionDevice struct {
	ProjectID        int64            `json:"-"`                          //项目id
	AreaID           int64            `json:"areaID,string,omitempty"`    //涉及到的区域ID
	AreaName         string           `json:"areaName,omitempty"`         //区域的名字
	ProductID        string           `json:"productID,omitempty"`        //产品id
	ProductName      string           `json:"productName,omitempty"`      //产品名称--填写产品ID的时候会自动补充
	SelectType       SelectType       `json:"selectType,omitempty"`       //设备选择方式
	DeviceName       string           `json:"deviceName,omitempty"`       //选择的设备列表 指定设备的时候才需要填写(如果设备换到其他区域里,这里删除该设备)
	DeviceAlias      string           `json:"deviceAlias,omitempty"`      //设备别名,只读
	GroupID          int64            `json:"groupID,omitempty"`          //分组id
	Type             ActionDeviceType `json:"type,omitempty"`             // 云端向设备发起属性控制: propertyControl  应用调用设备行为:action  todo:通知设备上报
	DataID           string           `json:"dataID,omitempty"`           // 属性的id及事件的id,不填则取values里面的
	DataName         string           `json:"dataName,omitempty"`         //对应的物模型定义,只读
	SchemaAffordance string           `json:"schemaAffordance,omitempty"` //只读,返回物模型定义
	Value            string           `json:"value,omitempty"`            //传的值
	Values           DeviceValues     `json:"values,omitempty"`           //如果需要控制多个参数
	Body             string           `json:"body,omitempty"`             //自定义字段
}

func (*ActionDevice) Execute

func (a *ActionDevice) Execute(ctx context.Context, repo ActionRepo) error

func (*ActionDevice) Validate

func (a *ActionDevice) Validate(repo CheckRepo) error

type ActionDeviceType

type ActionDeviceType = string
const (
	ActionDeviceTypePropertyControl ActionDeviceType = "propertyControl"
	ActionDeviceTypeAction          ActionDeviceType = "action"
)

type ActionNotify

type ActionNotify struct {
	Type       def.NotifyType    `json:"type"`
	NotifyCode def.NotifyCode    `json:"notifyCode"` //支持: ruleScene: 场景联动通知(多设备模式使用)   ruleDeviceAlarm: 设备告警通知(单设备模式使用)
	UserType   NotifyUserType    `json:"userType"`
	Accounts   []string          `json:"accounts,omitempty"` //通知的账号列表
	UserIDs    []string          `json:"userIDs,omitempty"`
	Params     map[string]string `json:"params,omitempty"` //需要填写告警的
	Str1       string            `json:"str1,omitempty"`
	Str2       string            `json:"str2,omitempty"`
	Str3       string            `json:"str3,omitempty"`
}

func (*ActionNotify) Execute

func (a *ActionNotify) Execute(ctx context.Context, repo ActionRepo) error

func (*ActionNotify) Validate

func (a *ActionNotify) Validate(repo CheckRepo) error

type ActionRepo

type ActionRepo struct {
	Info           *Info
	UserID         int64
	DeviceInteract deviceinteract.DeviceInteract
	DeviceM        devicemanage.DeviceManage
	DeviceCache    dmExport.DeviceCacheT
	ProductCache   dmExport.ProductCacheT
	DeviceG        devicegroup.DeviceGroup
	NotifyM        notifymanage.NotifyManage
	SceneExec      func(ctx context.Context, sceneID int64, status def.Bool) error
	AlarmExec      func(ctx context.Context, in AlarmSerial) error
	SaveLog        func(ctx context.Context, log *Log) error
}

type ActionScene

type ActionScene struct {
	AreaID    int64     `json:"areaID,string,omitempty"` //仅做记录
	SceneID   int64     `json:"sceneID,omitempty"`
	SceneType SceneType `json:"sceneType,omitempty"` //类型,后端会赋值
	SceneName string    `json:"sceneName,omitempty"` //更新及创建的时候后端会赋值
	Status    def.Bool  `json:"status,omitempty"`    //如果是自动化类型则为修改状态
}

func (*ActionScene) Execute

func (a *ActionScene) Execute(ctx context.Context, repo ActionRepo) error

func (*ActionScene) Validate

func (a *ActionScene) Validate(repo CheckRepo) error

type ActionType

type ActionType = string

操作执行器类型

const (
	ActionExecutorNotify ActionType = "notify" //通知
	ActionExecutorDelay  ActionType = "delay"  //延迟
	ActionExecutorDevice ActionType = "device" //设备输出
	ActionExecutorAlarm  ActionType = "alarm"  //告警
	ActionExecutorScene  ActionType = "scene"  //执行另一个场景
)

type Actions

type Actions []*Action

func (Actions) Execute

func (a Actions) Execute(ctx context.Context, repo ActionRepo) error

func (Actions) Validate

func (a Actions) Validate(repo CheckRepo) error

type AlarmDealStatus

type AlarmDealStatus = int64

type AlarmSerial

type AlarmSerial struct {
	Scene *Info           //场景ID
	Mode  ActionAlarmMode //告警模式
}

type CheckRepo

type CheckRepo struct {
	Ctx                context.Context
	DeviceCache        dmExport.DeviceCacheT
	UserShareCache     dmExport.UserShareCacheT
	ProductCache       dmExport.ProductCacheT
	ProductSchemaCache dmExport.SchemaCacheT
	ProjectCache       sysExport.ProjectCacheT
	DeviceMsg          devicemsg.DeviceMsg
	Common             common.Common
	GetSceneInfo       func(ctx context.Context, sceneID int64) (*Info, error)
	Info               *Info
}

type CmpType

type CmpType string
const (
	CmpTypeEq  CmpType = "eq"  //相等
	CmpTypeNot CmpType = "not" //不相等
	CmpTypeBtw CmpType = "btw" //在xx之间
	CmpTypeGt  CmpType = "gt"  //大于
	CmpTypeGte CmpType = "gte" //大于等于
	CmpTypeLt  CmpType = "lt"  //小于
	CmpTypeLte CmpType = "lte" //小于等于
	CmpTypeIn  CmpType = "in"  //在xx值之中,可以有n个参数
	CmpTypeAll CmpType = "all" //全部触发
)

func (CmpType) IsHit

func (t CmpType) IsHit(dataType schema.DataType, data any, values []string) bool

func (CmpType) Validate

func (t CmpType) Validate(values []string) error

type Conditions

type Conditions struct {
	Terms []Term       `json:"terms,omitempty"`
	Type  TermCondType `json:"type"`
}

func (*Conditions) IsHit

func (t *Conditions) IsHit(ctx context.Context, repo CheckRepo) bool

判断条件是否成立

func (*Conditions) Validate

func (t *Conditions) Validate(repo CheckRepo) error

type DateRange

type DateRange struct {
	Type      DateRangeType `json:"type"`                //日期类型 workday: 工作日 weekend: 周末 holiday: 节假日  customRange:自定义日期范围  customWeek:自定义周末
	StartDate string        `json:"startDate,omitempty"` //开始日期 2006-01-02
	EndDate   string        `json:"endDate,omitempty"`   //结束日期 2006-01-02
	Repeat    string        `json:"repeat,omitempty"`    //重复 二进制周一到周日 11111111 这个参数只有定时触发才有
}

func (*DateRange) IsHit

func (d *DateRange) IsHit(ctx context.Context, t time.Time, repo CheckRepo) bool

func (*DateRange) Validate

func (t *DateRange) Validate() error

type DateRangeType

type DateRangeType = string
const (
	DateRangeTypeAllDay      DateRangeType = "allDay"
	DateRangeTypeWorkDay     DateRangeType = "workday"
	DateRangeTypeWeekend     DateRangeType = "weekend"
	DateRangeTypeHoliday     DateRangeType = "holiday"
	DateRangeTypeCustomRange DateRangeType = "customRange"
	DateRangeTypeCustomWeek  DateRangeType = "customWeek"
)

type DeviceMode

type DeviceMode = string
const (
	DeviceModeSingle DeviceMode = "single" //单设备
	DeviceModeMulti  DeviceMode = "multi"  //多设备
)

type DeviceValue

type DeviceValue struct {
	DataID           string `json:"dataID"`           // 属性的id及事件的id
	DataName         string `json:"dataName"`         //对应的物模型定义,只读
	SchemaAffordance string `json:"schemaAffordance"` //只读,返回物模型定义
	Value            string `json:"value"`            //传的值
}

type DeviceValues

type DeviceValues = []*DeviceValue

type ExecType

type ExecType = string
const (
	ExecTypeAt       ExecType = "at"       //在时间点执行(默认)
	ExecTypeSunRises ExecType = "sunRises" //太阳升起
	ExecTypeSunSet   ExecType = "sunSet"   //太阳落下
	ExecTypeLoop     ExecType = "loop"     //间隔时间执行
)
const (
	TimeTypeSys               = "sys"      //系统时间
	TimeTypeSunRises ExecType = "sunRises" //太阳升起
	TimeTypeSunSet   ExecType = "sunSet"   //太阳落下
)

type FindWithTriggerDto

type FindWithTriggerDto struct {
	devices.Core
}

type FlowInfo

type FlowInfo struct {
	Type    string `json:"type"`    //流程类型 then
	SubType string `json:"subType"` //子类型 设备执行
	Info    string `json:"info"`    //设备执行类型为产品id
}

type If

type If struct {
	Triggers Triggers `json:"triggers,omitempty"`
}

func (*If) Validate

func (i *If) Validate(t SceneType, repo CheckRepo) error

type Info

type Info struct {
	ID          int64       `json:"id"`
	ProjectID   int64       `json:"projectID,string"`
	AreaID      int64       `json:"areaID,string"`
	HeadImg     string      `json:"headImg"`               // 头像
	FlowPath    []*FlowInfo `json:"flowPath"`              //执行路径
	DeviceMode  DeviceMode  `json:"deviceMode"`            //设备模式: 1:单设备 2:多设备
	ProductID   string      `json:"productID,omitempty"`   //产品id
	DeviceName  string      `json:"deviceName,omitempty"`  //设备名
	DeviceAlias string      `json:"deviceAlias,omitempty"` //设备别名,只读
	LastRunTime int64       `json:"lastRunTime"`
	Tag         string      `json:"tag"`
	Name        string      `json:"name"`
	Desc        string      `json:"desc"`
	CreatedTime time.Time   `json:"createdTime"`
	Type        SceneType   `json:"type"`
	If          If          `json:"if"`             //多种触发方式
	When        When        `json:"when"`           //手动触发模式不生效
	Then        Then        `json:"then"`           //触发后执行的动作
	Status      def.Bool    `json:"status"`         // 状态(1启用 2禁用)
	IsCommon    def.Bool    `json:"isCommon"`       // 是否是常用的
	Body        string      `json:"body,omitempty"` //自定义字段
	Log         *Log        `json:"-"`
}

多设备的场景联动

func (*Info) SetAccount

func (i *Info) SetAccount(ctx context.Context) context.Context

func (*Info) Validate

func (i *Info) Validate(repo CheckRepo) error

type Infos

type Infos []*Info

type Log

type Log struct {
	AreaID      int64        `json:"areaID,string"`
	SceneID     int64        `json:"sceneID"`
	Type        SceneType    `json:"type"`
	Status      def.Bool     `json:"status"`
	CreatedTime time.Time    `json:"createdTime"`
	Trigger     *LogTrigger  `json:"trigger,omitempty"`
	Actions     []*LogAction `json:"actions"`
	ActionMutex sync.RWMutex `json:"-"`
}

func NewLog

func NewLog(scene *Info) *Log

type LogAction

type LogAction struct {
	Type     ActionType       `json:"type"` //执行器类型 notify: 通知 delay:延迟  device:设备输出  alarm: 告警
	Device   *LogActionDevice `json:"device,omitempty"`
	Alarm    *LogActionAlarm  `json:"alarm,omitempty"`
	Delay    int64            `json:"delay,omitempty"` //秒数
	Scene    *LogActionScene  `json:"scene,omitempty"`
	Status   int64            `json:"status"`
	Code     int64            `json:"code"`
	Msg      string           `json:"msg"`
	MsgToken string           `json:"msgToken"`
}

type LogActionAlarm

type LogActionAlarm struct {
	Mode ActionAlarmMode `json:"mode"` //告警模式  trigger: 触发告警  relieve: 解除告警
}

type LogActionDevice

type LogActionDevice struct {
	ProductID   string                  `json:"productID"`             //产品id
	ProductName string                  `json:"productName"`           //产品名称--填写产品ID的时候会自动补充
	DeviceName  string                  `json:"deviceName"`            //选择的设备列表 指定设备的时候才需要填写(如果设备换到其他区域里,这里删除该设备)
	DeviceAlias string                  `json:"deviceAlias,omitempty"` //设备别名,只读
	Values      []*LogActionDeviceValue `json:"values"`                //传的值
}

type LogActionDeviceValue

type LogActionDeviceValue struct {
	DataID   string `json:"dataID"`   // 属性的id及事件的id,不填则取values里面的
	DataName string `json:"dataName"` //对应的物模型定义,只读
	Value    string `json:"value"`    //传的值
}

type LogActionScene

type LogActionScene struct {
	SceneID   int64  `json:"sceneID"`
	SceneName string `json:"sceneName"`
}

type LogTrigger

type LogTrigger struct {
	Type   TriggerType       `json:"type"`
	Time   time.Time         `json:"time"` //触发时间
	Device *LogTriggerDevice `json:"device,omitempty"`
}

type LogTriggerDevice

type LogTriggerDevice struct {
	ProductID   string            `json:"productID,omitempty"`   //产品id
	DeviceName  string            `json:"deviceName,omitempty"`  //选择的列表  选择的列表, fixedDevice类型是设备名列表
	DeviceAlias string            `json:"deviceAlias,omitempty"` //设备别名,只读
	Type        TriggerDeviceType `json:"type,omitempty"`        //触发类型  connected:上线 disConnected:下线 reportProperty:属性上报 reportEvent: 事件上报
	DataID      string            `json:"dataID"`                //选择为属性或事件时需要填该字段 属性的id及事件的id aa.bb.cc
	DataName    string            `json:"dataName"`              //对应的物模型定义,只读
	Value       string            `json:"value"`                 //触发的值
}

type NotifyUserType

type NotifyUserType = string

type RepeatType

type RepeatType = string
const (
	RepeatTypeWeek  RepeatType = "week"  //按周重复(默认)
	RepeatTypeMount RepeatType = "mount" //按月重复
)

type SceneType

type SceneType = string
const (
	//TriggerTypeDevice SceneType = "device"
	//TriggerTypeTimer  SceneType = "timer"
	SceneTypeManual SceneType = "manual" //手动触发 场景
	SceneTypeAuto   SceneType = "auto"   //自动化
)

type SelectType

type SelectType = string
const (
	SelectorDeviceAll SelectType = "all"   //产品下的所有设备
	SelectDeviceFixed SelectType = "fixed" //产品下的指定设备
	SelectArea        SelectType = "area"  //某个区域下的设备
	SelectGroup       SelectType = "group" //某个设备组的设备(支持不同产品的设备,但是需要有共同的公共物模型)
)

type StateKeep

type StateKeep struct {
	Type  StateKeepType `json:"type"`  //持续时间: duration  重复次数 repeating
	Value int64         `json:"value"` //持续的时间(秒)或重复的次数
}

StateKeep 状态保持

func (*StateKeep) Validate

func (s *StateKeep) Validate() error

type StateKeepType

type StateKeepType = string

type Term

type Term struct {
	Order      int64          `json:"order"`
	ColumnType TermColumnType `json:"columnType"`         //字段类型 property:属性 weather:天气
	Property   *TermProperty  `json:"property,omitempty"` //属性类型
	Weather    *TermWeather   `json:"weather,omitempty"`
	Time       *TermTime      `json:"time,omitempty"`
}

func (*Term) IsHit

func (t *Term) IsHit(ctx context.Context, repo CheckRepo) bool

func (*Term) Validate

func (t *Term) Validate(repo CheckRepo) error

type TermColumnType

type TermColumnType = string
const (
	TermColumnTypeProperty TermColumnType = "property"
	TermColumnTypeEvent    TermColumnType = "event"
	//TermColumnTypeReportTime TermColumnType = "reportTime"
	TermColumnTypeTime    TermColumnType = "time"
	TermColumnTypeWeather TermColumnType = "weather"
)

type TermCondType

type TermCondType string
const (
	TermConditionTypeOr  TermCondType = "or"
	TermConditionTypeAnd TermCondType = "and"
)

type TermProperty

type TermProperty struct {
	AreaID           int64    `json:"areaID,string,omitempty"` //仅做记录
	ProductID        string   `json:"productID,omitempty"`     //产品id
	DeviceName       string   `json:"deviceName,omitempty"`
	DeviceAlias      string   `json:"deviceAlias,omitempty"`
	DataID           string   `json:"dataID,omitempty"` //属性的id   aa.bb.cc
	DataName         string   `json:"dataName,omitempty"`
	SchemaAffordance string   `json:"schemaAffordance,omitempty"` //只读,返回物模型定义
	TermType         CmpType  `json:"termType,omitempty"`         //动态条件类型  eq: 相等  not:不相等  btw:在xx之间  gt: 大于  gte:大于等于 lt:小于  lte:小于等于   in:在xx值之间
	Values           []string `json:"values,omitempty"`           //条件值 参数根据动态条件类型会有多个参数
}

TermProperty 物模型类型 属性

func (*TermProperty) IsHit

func (c *TermProperty) IsHit(ctx context.Context, columnType TermColumnType, repo CheckRepo) bool

func (*TermProperty) Validate

func (c *TermProperty) Validate(repo CheckRepo) error

type TermTime

type TermTime struct {
	Type     TimeType `json:"type"`     //时间的类型
	TermType CmpType  `json:"termType"` //动态条件类型  eq: 相等  not:不相等  btw:在xx之间  gt: 大于  gte:大于等于 lt:小于  lte:小于等于   in:在xx值之间
	/*
			条件值 参数根据动态条件类型会有多个参数
		如果是sys类型 则为触发时间和values中的时间进行比较,比如 7点-8点 ,
		如果是太阳起和落下,如落下后30分钟内则为 now btw  0, 30*60
	*/
	Values []string `json:"values"`
}

TermTime 时间执行条件

func (*TermTime) IsHit

func (c *TermTime) IsHit(ctx context.Context, repo CheckRepo) bool

func (*TermTime) Validate

func (c *TermTime) Validate(repo CheckRepo) error

type TermWeather

type TermWeather struct {
	Type     WeatherType `json:"type"`     //天气的类型
	TermType CmpType     `json:"termType"` //动态条件类型  eq: 相等  not:不相等  btw:在xx之间  gt: 大于  gte:大于等于 lt:小于  lte:小于等于   in:在xx值之间
	Values   []string    `json:"values"`   //条件值 参数根据动态条件类型会有多个参数
}

TermProperty 物模型类型 属性

func (*TermWeather) IsHit

func (c *TermWeather) IsHit(ctx context.Context, repo CheckRepo) bool

func (*TermWeather) Validate

func (c *TermWeather) Validate(repo CheckRepo) error

type Then

type Then struct {
	Actions Actions `json:"actions"` //执行内容
}

func (*Then) Execute

func (t *Then) Execute(ctx context.Context, repo ActionRepo) error

func (*Then) GetFlowPath

func (t *Then) GetFlowPath() (ret []*FlowInfo)

func (*Then) Validate

func (t *Then) Validate(repo CheckRepo) error

type TimeRange

type TimeRange struct {
	Type      TimeRangeType `json:"type"`                //时间类型  allDay:全天 light:白天(从日出到日落) night:夜间(从日落到日出) customRange:自定义范围
	StartTime int64         `json:"startTime,omitempty"` //自定义开始时间 从0点加起来的秒数
	EndTime   int64         `json:"endTime,omitempty"`   //自定义结束时间 从0点加起来的秒数
}

TimeRange 时间范围 只支持后面几种特殊字符:* - ,

func (*TimeRange) IsHit

func (d *TimeRange) IsHit(ctx context.Context, t time.Time, repo CheckRepo) bool

func (*TimeRange) Validate

func (t *TimeRange) Validate() error

type TimeRangeType

type TimeRangeType = string
const (
	TimeRangeTypeAllDay      TimeRangeType = "allDay"
	TimeRangeTypeLight       TimeRangeType = "light" //todo
	TimeRangeTypeNight       TimeRangeType = "night" //todo
	TimeRangeTypeCustomRange TimeRangeType = "customRange"
)

type TimeType

type TimeType = string

type Trigger

type Trigger struct {
	Type    TriggerType     `json:"type"`
	Order   int64           `json:"order"`
	AreaID  int64           `json:"areaID,string"`    //涉及到的区域ID
	Device  *TriggerDevice  `json:"device,omitempty"` //设备触发
	Timer   *TriggerTimer   `json:"timer,omitempty"`  //定时触发
	Weather *TriggerWeather `json:"weather,omitempty"`
}

func (*Trigger) Validate

func (t *Trigger) Validate(repo CheckRepo) error

type TriggerDevice

type TriggerDevice struct {
	StateKeep        *StateKeep        `json:"stateKeep,omitempty"`   //状态保持
	ProductID        string            `json:"productID,omitempty"`   //产品id
	SelectType       SelectType        `json:"selectType"`            //设备选择方式  all: 全部 fixed:指定的设备
	GroupID          int64             `json:"groupID,omitempty"`     //分组id
	DeviceName       string            `json:"deviceName,omitempty"`  //选择的列表  选择的列表, fixedDevice类型是设备名列表
	DeviceAlias      string            `json:"deviceAlias,omitempty"` //设备别名,只读
	Type             TriggerDeviceType `json:"type,omitempty"`        //触发类型  connected:上线 disConnected:下线 reportProperty:属性上报 reportEvent: 事件上报
	DataID           string            `json:"dataID"`                //选择为属性或事件时需要填该字段 属性的id及事件的id aa.bb.cc
	SchemaAffordance string            `json:"schemaAffordance"`      //只读,返回物模型定义
	DataName         string            `json:"dataName"`              //对应的物模型定义,只读
	TermType         CmpType           `json:"termType"`              //动态条件类型  eq: 相等  not:不相等  btw:在xx之间  gt: 大于  gte:大于等于 lt:小于  lte:小于等于   in:在xx值之间
	Values           []string          `json:"values"`                //比较条件列表
	Body             string            `json:"body,omitempty"`        //自定义字段
	Param            string            `json:"-"`                     //触发的参数
}

func (*TriggerDevice) IsHit

func (t *TriggerDevice) IsHit(model *schema.Model, dataID string, param any) bool

func (*TriggerDevice) Validate

func (t *TriggerDevice) Validate(repo CheckRepo) error

type TriggerDeviceType

type TriggerDeviceType = string
const (
	TriggerDeviceTypeConnected      TriggerDeviceType = "connected"
	TriggerDeviceTypeDisConnected   TriggerDeviceType = "disConnected"
	TriggerDeviceTypePropertyReport TriggerDeviceType = "propertyReport"
	TriggerDeviceTypeEventReport    TriggerDeviceType = "eventReport"
)

type TriggerDevices

type TriggerDevices []*TriggerDevice

func (TriggerDevices) IsTriggerWithConn

func (t TriggerDevices) IsTriggerWithConn(device devices.Core, operator TriggerDeviceType) bool

IsTrigger 判断触发器是否命中

func (TriggerDevices) IsTriggerWithProperty

func (t TriggerDevices) IsTriggerWithProperty(model *schema.Model, reportInfo *application.PropertyReport) bool

IsTrigger 判断触发器是否命中属性上报类型

func (TriggerDevices) Validate

func (t TriggerDevices) Validate(repo CheckRepo) error

type TriggerTimer

type TriggerTimer struct {
	ExecType      ExecType   `json:"execType"`                //执行方式
	ExecAdd       int64      `json:"execAdd,omitempty"`       //如果是日出日落模式,则为日出日落前后的秒数
	ExecAt        int64      `json:"execAt,omitempty"`        //执行的时间点 从0点加起来的秒数 如 1点就是 1*60*60
	ExecLoopStart int64      `json:"execLoopStart,omitempty"` //循环执行起始时间配置
	ExecLoopEnd   int64      `json:"execLoopEnd,omitempty"`
	ExecLoop      int64      `json:"execLoop,omitempty"` //循环时间间隔
	RepeatType    RepeatType `json:"repeatType,omitempty"`
	ExecRepeat    string     `json:"execRepeat,omitempty"` //二进制周一到周日 11111111 或二进制月一到月末
}

TriggerTimer 定时器类型

func (*TriggerTimer) Validate

func (t *TriggerTimer) Validate(repo CheckRepo) error

type TriggerTimers

type TriggerTimers []*TriggerTimer

func (TriggerTimers) Validate

func (t TriggerTimers) Validate(repo CheckRepo) error

type TriggerType

type TriggerType = string
const (
	TriggerTypeDevice  TriggerType = "device"
	TriggerTypeTimer   TriggerType = "timer"
	TriggerTypeWeather TriggerType = "weather"
)

type TriggerWeather

type TriggerWeather struct {
	TermWeather
}

TriggerWeather 定时器类型

func (*TriggerWeather) Validate

func (t *TriggerWeather) Validate(repo CheckRepo) error

type TriggerWeathers

type TriggerWeathers []*TriggerWeather

func (TriggerWeathers) Validate

func (t TriggerWeathers) Validate(repo CheckRepo) error

type Triggers

type Triggers []*Trigger

func (Triggers) Validate

func (t Triggers) Validate(repo CheckRepo) error

type WeatherType

type WeatherType = string

type When

type When struct {
	ValidRanges   WhenRanges `json:"validRanges,omitempty"`   //生效时间段
	InvalidRanges WhenRanges `json:"invalidRanges,omitempty"` //无效时间段(最高优先级)
	Conditions    Conditions `json:"conditions,omitempty"`    //条件
}

func (*When) IsHit

func (w *When) IsHit(ctx context.Context, t time.Time, repo CheckRepo) bool

func (*When) Validate

func (w *When) Validate(repo CheckRepo) error

type WhenRange

type WhenRange struct {
	Order     int64     `json:"order"`
	Type      string    `json:"type"` //范围类型 date: 日期范围 time: 时间范围
	DateRange DateRange `json:"dateRange,omitempty"`
	TimeRange TimeRange `json:"timeRange,omitempty"`
}

func (*WhenRange) IsHit

func (w *WhenRange) IsHit(ctx context.Context, t time.Time, repo CheckRepo) bool

func (*WhenRange) Validate

func (w *WhenRange) Validate() error

type WhenRanges

type WhenRanges []WhenRange

func (WhenRanges) IsHit

func (w WhenRanges) IsHit(ctx context.Context, t time.Time, repo CheckRepo) bool

func (WhenRanges) Validate

func (w WhenRanges) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL