Documentation ¶
Index ¶
- Variables
- type Logic
- func (l *Logic) AddRule(name string) *Rule
- func (l *Logic) EvaluateRules(ctx context.Context)
- func (l *Logic) GetRules() Rules
- func (l *Logic) Load() error
- func (l *Logic) OnReportState(callback func(string, devices.State))
- func (l *Logic) OnTriggerDestination(callback func(string, string) error)
- func (l *Logic) Save() error
- func (l *Logic) SetRules(rules Rules)
- func (l *Logic) Start(ctx context.Context)
- func (l *Logic) UpdateDevice(dev *devices.Device)
- type Rule
- func (r *Rule) Active() bool
- func (r *Rule) Cancel()
- func (r *Rule) Conditions() map[string]bool
- func (r *Rule) Eval(devices *devices.List, rules map[string]bool) (bool, error)
- func (r *Rule) Expression() string
- func (r *Rule) For() stypes.Duration
- func (r *Rule) Name() string
- func (r *Rule) Pending() bool
- func (r *Rule) Run(store *SavedStateStore, sender websocket.Sender, ...)
- func (r *Rule) SetActive(a bool)
- func (r *Rule) SetPending(a bool)
- func (r *Rule) SetUuid(uuid string)
- func (r *Rule) Stop()
- func (r *Rule) Type() string
- func (r *Rule) Uuid() string
- type Rules
- type SavedState
- type SavedStateStore
- type SavedStates
- type Scheduler
- func (s *Scheduler) AddTask(name string) *Task
- func (s *Scheduler) Load() error
- func (s *Scheduler) RemoveTask(uuid string)
- func (s *Scheduler) Save() error
- func (s *Scheduler) ScheduleTask(t *Task)
- func (s *Scheduler) SetTasks(t Tasks)
- func (s *Scheduler) Start(parentCtx context.Context)
- func (s *Scheduler) Stop()
- func (s *Scheduler) Task(uuid string) *Task
- func (s *Scheduler) Tasks() Tasks
- type Task
- type Tasks
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrExpressionNotBool = fmt.Errorf("invalid result of expression. Only bool expressions are valid")
Functions ¶
This section is empty.
Types ¶
type Logic ¶
type Logic struct { StateStore *SavedStateStore Rules map[string]*Rule // ActionProgressChan chan ActionProgress sync.RWMutex sync.WaitGroup WebsocketSender websocket.Sender // contains filtered or unexported fields }
Logic is the main struct.
func New ¶
func New(sss *SavedStateStore, websocketSender websocket.Sender) *Logic
New returns a new logic that is ready to use.
func (*Logic) EvaluateRules ¶
EvaluateRules loops over each rule and run evaluation on them.
func (*Logic) OnTriggerDestination ¶
func (*Logic) UpdateDevice ¶
UpdateDevice update the state in the logic store with the new state from the device.
type Rule ¶
type Rule struct { Name_ string `json:"name"` Uuid_ string `json:"uuid"` Active_ bool `json:"active"` Pending_ bool `json:"pending"` Enabled bool `json:"enabled"` Expression_ string `json:"expression"` Conditions_ map[string]bool `json:"conditions"` Actions_ []string `json:"actions"` Labels_ models.Labels `json:"labels"` For_ stypes.Duration `json:"for"` Type_ string `json:"type"` Destinations_ []string `json:"destinations"` sync.RWMutex // contains filtered or unexported fields }
func (*Rule) Conditions ¶
func (*Rule) Expression ¶
func (*Rule) SetPending ¶
type SavedState ¶
type SavedStateStore ¶
type SavedStateStore struct { State SavedStates sync.RWMutex }
func NewSavedStateStore ¶
func NewSavedStateStore() *SavedStateStore
func (*SavedStateStore) All ¶
func (sss *SavedStateStore) All() SavedStates
func (*SavedStateStore) Get ¶
func (sss *SavedStateStore) Get(id string) *SavedState
func (*SavedStateStore) Load ¶
func (sss *SavedStateStore) Load() error
func (*SavedStateStore) Save ¶
func (sss *SavedStateStore) Save() error
func (*SavedStateStore) SetState ¶
func (sss *SavedStateStore) SetState(s SavedStates)
type SavedStates ¶
type SavedStates map[string]*SavedState
type Scheduler ¶
type Scheduler struct { Cron *cron.Cron sync.RWMutex SavedStateStore *SavedStateStore // contains filtered or unexported fields }
Scheduler that schedule running saved state actions.
func NewScheduler ¶
func NewScheduler(savedStateStore *SavedStateStore, sender websocket.Sender, logic *Logic) *Scheduler
func (*Scheduler) RemoveTask ¶
func (*Scheduler) ScheduleTask ¶
type Task ¶
type Task struct { XName string `json:"name"` XUuid string `json:"uuid"` Actions []string `json:"actions"` When string `json:"when"` Enabled bool `json:"enabled"` Expression_ string `json:"expression"` sync.RWMutex // contains filtered or unexported fields }
Task is a task that can be scheduled using scheduler.
func (*Task) Expression ¶ added in v2.2.0
Click to show internal directories.
Click to hide internal directories.