scene

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package scene 执行动作

Package scene 执行动作

Package scene 触发条件

Package scene 触发器

Index

Constants

View Source
const (
	StateKeepTypeDuration  = "duration"
	StateKeepTypeRepeating = "repeating"
)

Variables

This section is empty.

Functions

func TermCompareAll added in v0.4.1

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

Types

type Action

type Action struct {
	Executor ActionExecutor `json:"executor"` //执行器类型 notify: 通知 delay:延迟  device:设备输出  alarm: 告警
	Delay    *UnitTime      `json:"delay"`
	Alarm    *ActionAlarm   `json:"alarm"`
	Device   *ActionDevice  `json:"device"`
}

func (*Action) Execute added in v0.4.1

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

执行操作

func (*Action) Validate

func (a *Action) Validate() error

type ActionAlarm

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

func (*ActionAlarm) Execute added in v0.4.1

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 added in v0.4.1

type ActionDevice struct {
	ProductID      string           `json:"productID"`      //产品id
	Selector       DeviceSelector   `json:"selector"`       //设备选择方式   fixed:指定的设备
	SelectorValues []string         `json:"selectorValues"` //选择的列表  选择的列表, fixed类型是设备名列表
	Type           ActionDeviceType `json:"type"`           // 云端向设备发起属性控制: propertyControl  应用调用设备行为:action  todo:通知设备上报
	DataID         string           `json:"dataID"`         // 属性的id及事件的id
	Value          string           `json:"value"`          //传的值
}

func (*ActionDevice) Execute added in v0.4.1

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

func (*ActionDevice) Validate added in v0.4.1

func (a *ActionDevice) Validate() error

type ActionDeviceType added in v0.4.1

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

type ActionExecutor

type ActionExecutor string

操作执行器类型

const (
	ActionExecutorNotify ActionExecutor = "notify" //通知
	ActionExecutorDelay  ActionExecutor = "delay"  //延迟
	ActionExecutorDevice ActionExecutor = "device" //设备输出
	ActionExecutorAlarm  ActionExecutor = "alarm"  //告警
)

type ActionRepo added in v0.4.1

type ActionRepo struct {
	DeviceInteract deviceinteract.DeviceInteract
	DeviceM        devicemanage.DeviceManage
	Alarm          AlarmRepo
	Device         devices.Core
	Serial         Serial
	Scene          *Info
}

type Actions

type Actions []*Action

func (Actions) Execute added in v0.4.1

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

func (Actions) Validate

func (a Actions) Validate() error

type AlarmRelieve added in v0.4.1

type AlarmRelieve struct {
	SceneID   int64  //场景ID
	SceneName string //场景名称
}

type AlarmRepo added in v0.4.1

type AlarmRepo interface {
	//告警触发
	AlarmTrigger(ctx context.Context, in TriggerSerial) error
	//告警解除
	AlarmRelieve(ctx context.Context, in AlarmRelieve) error
}

type CmpType added in v0.4.1

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个参数
)

func (CmpType) IsHit added in v0.4.1

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

func (CmpType) Validate added in v0.4.1

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

type ColumnSchema added in v0.4.1

type ColumnSchema struct {
	ProductID  string   `json:"productID"` //产品id
	DeviceName string   `json:"deviceName"`
	DataID     []string `json:"dataID"`   //属性的id及事件的id aa.bb.cc
	TermType   CmpType  `json:"termType"` //动态条件类型  eq: 相等  not:不相等  btw:在xx之间  gt: 大于  gte:大于等于 lt:小于  lte:小于等于   in:在xx值之间
	Values     []string `json:"values"`   //条件值 参数根据动态条件类型会有多个参数
}

ColumnSchema 物模型类型 属性,事件

func (*ColumnSchema) IsHit added in v0.4.1

func (c *ColumnSchema) IsHit(ctx context.Context, columnType TermColumnType, repo TermRepo) bool

func (*ColumnSchema) Validate added in v0.4.1

func (c *ColumnSchema) Validate() error

type DeviceOperationOperator

type DeviceOperationOperator string
const (
	DeviceOperationOperatorConnected      DeviceOperationOperator = "connected"
	DeviceOperationOperatorDisConnected   DeviceOperationOperator = "disConnected"
	DeviceOperationOperatorReportProperty DeviceOperationOperator = "reportProperty"
)

type DeviceRepo added in v0.4.1

type DeviceRepo interface {
	Insert(ctx context.Context, info *Info) error
	Update(ctx context.Context, info *Info) error
	Delete(ctx context.Context, id int64) error
	GetInfos(ctx context.Context, device devices.Core, operator DeviceOperationOperator, dataID string) (Infos, error)
}

type DeviceSelector added in v0.4.1

type DeviceSelector string
const (
	DeviceSelectorAll   DeviceSelector = "all"
	DeviceSelectorFixed DeviceSelector = "fixed"
)

type FindWithTriggerDto added in v0.4.1

type FindWithTriggerDto struct {
	devices.Core
}

type Info

type Info struct {
	ID          int64       `json:"id"`
	Name        string      `json:"name"`
	Desc        string      `json:"desc"`
	CreatedTime time.Time   `json:"createdTime"`
	TriggerType TriggerType `json:"triggerType"` //触发类型 device: 设备触发 timer: 定时触发 manual:手动触发
	Trigger     Trigger     `json:"trigger"`     //多种触发方式
	When        Terms       `json:"when"`
	Then        Actions     `json:"then"`
	Status      int64       `json:"state"` // 状态(1启用 2禁用)
}

func (*Info) Validate

func (i *Info) Validate() error

type InfoFilter

type InfoFilter struct {
	Name        string `json:"name"`
	Status      int64
	TriggerType TriggerType
	AlarmID     int64 //绑定的告警id
}

type Infos added in v0.4.1

type Infos []*Info

type OperationSchema added in v0.4.1

type OperationSchema struct {
	DataID    []string   `json:"dataID"`    //选择为属性或事件时需要填该字段 属性的id及事件的id aa.bb.cc
	TermType  CmpType    `json:"termType"`  //动态条件类型  eq: 相等  not:不相等  btw:在xx之间  gt: 大于  gte:大于等于 lt:小于  lte:小于等于   in:在xx值之间
	Values    []string   `json:"values"`    //比较条件列表
	StateKeep *StateKeep `json:"stateKeep"` //状态保持 todo
}

func (*OperationSchema) IsHit added in v0.4.1

func (o *OperationSchema) IsHit(dataID string, param application.ParamValue) bool

func (*OperationSchema) Validate added in v0.4.1

func (o *OperationSchema) Validate() error

type Repo

type Repo interface {
	Insert(ctx context.Context, info *Info) (id int64, err error)
	Update(ctx context.Context, info *Info) error
	Delete(ctx context.Context, id int64) error
	FindOne(ctx context.Context, id int64) (*Info, error)
	FindOneByName(ctx context.Context, name string) (*Info, error)
	FindByFilter(ctx context.Context, filter InfoFilter, page *def.PageInfo) (Infos, error)
	CountByFilter(ctx context.Context, filter InfoFilter) (size int64, err error)
}

type Serial added in v0.4.1

type Serial interface {
	GenSerial() string
}

type StateKeep added in v0.4.1

type StateKeep struct {
	Type  StateKeepType `json:"type"`  //持续时间: duration  重复次数 repeating
	Value int64         `json:"value"` //持续的时间或重复的次数
	Unit  TimeUnit      `json:"unit"`  //时间单位 second:秒  minute:分钟  hour:小时  week:星期 month:月
}

StateKeep 状态保持

func (*StateKeep) Validate added in v0.4.1

func (s *StateKeep) Validate() error

type StateKeepType added in v0.4.1

type StateKeepType string

func (StateKeepType) Validate added in v0.4.1

func (s StateKeepType) Validate() error

type Term

type Term struct {
	ColumnType        TermColumnType    `json:"columnType"`        //字段类型 property:属性 event:事件 sysTime:系统时间
	ColumnSchema      *ColumnSchema     `json:"columnSchema"`      //物模型类型
	ColumnTime        *TimeRange        `json:"columnTime"`        //时间类型 只支持后面几种特殊字符:*  - ,
	NextCondition     TermConditionType `json:"netCondition"`      //和下个条件的关联类型  or  and
	ChildrenCondition TermConditionType `json:"childrenCondition"` //和嵌套条件的关联类型  or  and
	Terms             Terms             `json:"terms"`             //嵌套条件
}

func (*Term) IsHit added in v0.4.1

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

func (*Term) Validate

func (t *Term) Validate() error

type TermColumnType

type TermColumnType string
const (
	TermColumnTypeProperty TermColumnType = "property"
	TermColumnTypeEvent    TermColumnType = "event"
	//TermColumnTypeReportTime TermColumnType = "reportTime"
	TermColumnTypeSysTime TermColumnType = "sysTime"
)

func (TermColumnType) Validate added in v0.4.1

func (t TermColumnType) Validate() error

type TermConditionType

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

type TermRepo added in v0.4.1

type TermRepo struct {
	DeviceMsg  devicemsg.DeviceMsg
	SchemaRepo schema.ReadRepo
}

TermRepo 场景运行需要用到的对外仓储

type Terms

type Terms []*Term

func (Terms) IsHit added in v0.4.1

func (t Terms) IsHit(ctx context.Context, repo TermRepo) bool

判断条件是否成立

func (Terms) Validate

func (t Terms) Validate() error

type TimeRange added in v0.4.1

type TimeRange struct {
	Type string `json:"type"` //时间类型 cron
	Cron string `json:"cron"` //  cron表达式
}

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

func (*TimeRange) IsHit added in v0.4.1

func (t *TimeRange) IsHit(tim time.Time) bool

func (*TimeRange) Validate added in v0.4.1

func (t *TimeRange) Validate() error

type TimeUnit added in v0.4.1

type TimeUnit string
const (
	TimeUnitSeconds TimeUnit = "seconds"
	TimeUnitMinutes TimeUnit = "minutes"
	TimeUnitHours   TimeUnit = "hours"
)

func (TimeUnit) Validate added in v0.4.1

func (t TimeUnit) Validate() error

type Timer added in v0.4.1

type Timer struct {
	Type string `json:"type"` //时间类型 cron
	Cron string `json:"cron"` //  cron表达式
}

Timer 定时器类型

func (*Timer) Validate added in v0.4.1

func (t *Timer) Validate() error

type Trigger

type Trigger struct {
	Device TriggerDevices `json:"device"`
	Timer  *Timer         `json:"timer"`
}

func (*Trigger) Validate

func (t *Trigger) Validate(triggerType TriggerType) error

type TriggerDevice

type TriggerDevice struct {
	ProductID       string                  `json:"productID"`       //产品id
	Selector        DeviceSelector          `json:"selector"`        //设备选择方式  all: 全部 fixed:指定的设备
	SelectorValues  []string                `json:"selectorValues"`  //选择的列表  选择的列表, fixed类型是设备名列表
	Operator        DeviceOperationOperator `json:"operator"`        //触发类型  connected:上线 disConnected:下线 reportProperty:属性上报 reportEvent: 事件上报
	OperationSchema *OperationSchema        `json:"operationSchema"` //物模型类型的具体操作 reportProperty:属性上报 reportEvent: 事件上报
}

func (*TriggerDevice) Validate

func (t *TriggerDevice) Validate() error

type TriggerDevices added in v0.4.1

type TriggerDevices []*TriggerDevice

func (TriggerDevices) IsTriggerWithConn added in v0.4.1

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

IsTrigger 判断触发器是否命中

func (TriggerDevices) IsTriggerWithProperty added in v0.4.1

func (t TriggerDevices) IsTriggerWithProperty(reportInfo *application.PropertyReport) bool

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

func (TriggerDevices) Validate added in v0.4.1

func (t TriggerDevices) Validate() error

type TriggerSerial added in v0.4.1

type TriggerSerial struct {
	SceneID     int64  //场景ID
	SceneName   string //场景名称
	TriggerType int64  //触发类型(设备触发1,其他2)
	Device      devices.Core
	Serial      string //流水
	Desc        string //说明
}

type TriggerType

type TriggerType string
const (
	TriggerTypeDevice TriggerType = "device"
	TriggerTypeTimer  TriggerType = "timer"
	TriggerTypeManual TriggerType = "manual"
)

type UnitTime added in v0.4.1

type UnitTime struct {
	Time int64    `json:"time"` //延迟时间
	Unit TimeUnit `json:"unit"` //时间单位 second:秒  minute:分钟  hour:小时  week:星期 month:月
}

func (*UnitTime) Execute added in v0.4.1

func (a *UnitTime) Execute()

func (*UnitTime) Validate added in v0.4.1

func (a *UnitTime) Validate() error

Jump to

Keyboard shortcuts

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