Documentation ¶
Index ¶
- Variables
- func DefaultLogger() logr.Logger
- func Entities(entities ...string) []string
- func Eval(exp ...string) []string
- func Evaluate(states States, eval string) bool
- func Evaluates(states States, eval []string) bool
- func Periodics(times ...string) []string
- type Command
- type CommandType
- type Config
- type Device
- type GoScript
- func (gs *GoScript) AddDevice(dev *device.Device) (*Device, error)
- func (gs *GoScript) AddTrigger(tr *Trigger)
- func (gs *GoScript) AddTriggers(triggers ...*Trigger)
- func (gs *GoScript) CallService(service services.Service)
- func (gs *GoScript) Close()
- func (gs *GoScript) Connect() error
- func (gs *GoScript) GetAreaDomain(area, domain string) []string
- func (gs *GoScript) GetDevice(entity string) (*Device, error)
- func (gs *GoScript) GetDomainStates(domainentity []string) *States
- func (gs *GoScript) GetModule(key string) (interface{}, error)
- func (gs *GoScript) GetState(domain, entityid string) *State
- func (gs *GoScript) GetStates(domainentity []string) *States
- func (gs *GoScript) Logger() logr.Logger
- func (gs *GoScript) RemoveTrigger(t *Trigger)
- func (gs *GoScript) TaskMQTT(tr *Trigger) func(message mqtt.Message, client mqtt.Client)
- type Modules
- type Periodic
- type ServiceChan
- type State
- type States
- func (s *States) Combine(cs *States)
- func (s *States) Entities() []string
- func (s *States) Find(entities []string) map[string]*State
- func (s *States) FindDomainMap(keys []string) map[string]*State
- func (s *States) Get(key string) (*State, bool)
- func (s *States) Insert(ps *State) *State
- func (s *States) Map() map[string]*State
- func (s *States) Slice() []*State
- func (s *States) SubSet(entities []string) States
- func (s *States) Upsert(ps *State) *State
- func (s *States) Where(state string) *States
- type Task
- func (t *Task) Cancelled() bool
- func (t *Task) Context() context.Context
- func (t *Task) Sleep(timeout time.Duration)
- func (t *Task) UUID() uuid.UUID
- func (t *Task) WaitUntil(entityID string, eval []string, timeout time.Duration) bool
- func (t *Task) While(entityID string, eval []string, whileFunc WhileFunc)
- type TaskFunc
- type Trigger
- type TriggerFunc
- type Unique
- type WhileFunc
Constants ¶
This section is empty.
Variables ¶
var (
ErrModuleNotFound = errors.New("module not found")
)
Functions ¶
func DefaultLogger ¶ added in v0.2.0
Types ¶
type Command ¶ added in v0.2.2
type Command struct {
// contains filtered or unexported fields
}
func GetStatesCommand ¶ added in v0.2.2
func ServiceCommand ¶ added in v0.2.2
type CommandType ¶ added in v0.2.2
type CommandType int
const ( CommandTypeService CommandType = iota CommandTypeGetStates CommandType = iota )
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
func (*Device) GetEntities ¶ added in v0.2.1
func (*Device) GetUniqueID ¶
type GoScript ¶
type GoScript struct { ServiceChan ServiceChan // contains filtered or unexported fields }
GoScript is the base type for GoScript holding all the state and functionality for interacting with Home Assistant
func (*GoScript) AddTrigger ¶
AddTrigger adds a trigger to the trigger map. There is no validation of a trigger.
func (*GoScript) AddTriggers ¶
AddTriggers helper function to add multiple triggers
func (*GoScript) CallService ¶
func (*GoScript) Connect ¶
Connect connects to the WebSocket server and MQTT server as setup all options need to be passed before firing connect, anything added after will have odd effects
func (*GoScript) GetAreaDomain ¶ added in v0.1.2
func (*GoScript) GetDomainStates ¶
func (*GoScript) GetModule ¶
GetModule returns the config module in interface{} form, must be cast to module type
func (*GoScript) RemoveTrigger ¶
RemoveTrigger can be used to remove a trigger while program is running.
type ServiceChan ¶
ServiceChan is a channel to send services to be run to
type State ¶
type State struct { DomainEntity string Domain string Entity string State string Attributes map[string]interface{} }
func MessageState ¶
type States ¶
type States struct {
// contains filtered or unexported fields
}
func (*States) Combine ¶ added in v0.2.2
Combine takes two States objects and merges them, passed object will overwrite a state in current object
func (*States) FindDomainMap ¶ added in v0.2.4
FindDomainMap returns a map of the states for the passed domain
func (*States) Insert ¶ added in v0.2.3
Insert only adds to the map if something does not exist already. Returns what is in the map whether added or not
func (*States) SubSet ¶ added in v0.2.2
SubSet returns a new States which contains a subset of the current states based on entities passed
type Task ¶
type Task struct { Message *model.Message MqttMessage mqtt.Message States States ServiceChan ServiceChan // contains filtered or unexported fields }
Task is used within a TriggerFunc to give information about the task. Message is the message that triggered the task. States is all the States defined when the trigger was created. States gets updated each time the methods are run. Task contains 3 methods: Sleep, WaitUntil and While to help processing within a function and handle being able to properly kill the task externally.
func (*Task) Sleep ¶
Sleep waits for the timeout to occur and panics if the context is cancelled The panic is caught by a recover
type TaskFunc ¶ added in v0.2.3
type TaskFunc func(t *Task)
TaskFunc is used to include a task object in MQTT command functions.
type Trigger ¶
type Trigger struct { Unique *Unique Triggers []string DomainTrigger []string // DomainTrigger, triggers of everything in the domain, also attaches all States for the domain Periodic States []string DomainStates []string Eval []string Func TriggerFunc // contains filtered or unexported fields }
Trigger takes in trigger items, domains or a schedule and runs a function based on any variation of the inputs.
If Unique is not nil then the trigger function will either kill off currently running trigger functions of the same type or kill itself.
Triggers can be on Entity's (full domain.entity format), Domains or on a Periodic schedule. Periodics do not get run through Eval's but it is best to handle all evaluation within the function for Periodics mixed with other trigger types to ensure consistent results.
States is a list of entities to which the state will be available within the task function. All triggers are automatically included in the list. DomainStates allows you to specify a whole domain to be included in the States.
Evaluation is done through a list of strings that are run through github.com/antonmedv/expr to evaluate the output. Like with PyScript type is important in the evaluation scripts. Check out github.com/antonmedv/expr for more details on casting and converting. You cannot mix types in a single evaluation so `state == "on" || state > 10` will always return false due to failure parsing the evaluation. Attributes are available inside the evaluations so `color_temp > 100` will work as long as color_temp exists in the attributes of the entity and the data type is a float
Func is the function to run when the criteria are met. Within the trigger function a *Task is available to give information on the trigger. Killing the triggerfunc panics to exit. The runner recovers this panic, this also means that if your code panics the whole program will not crash but will continue. Panic will be written to the logs.
type TriggerFunc ¶
type TriggerFunc func(t *Task)
TriggerFunc is the function to run when the criteria are met. Within the trigger function a *Task is available. See Task for more information on what is available in Task.
type Unique ¶
type Unique struct { KillMe bool Wait bool UUID *uuid.UUID // contains filtered or unexported fields }
The Unique task will wait until the currently running task finishes to start. To quickly kill tasks that are running it is important to only use the task methods within a trigger function instead of time.Sleep. If Unique.KillMe is set to true the task will not be setup and will not run if another task is running of the same type. Unique.UUID is used to link multiple triggers together. For example two triggers that control the same light and you only want one of the trigger functions to run at a time. Unique.Wait waits until the current task is finished before running, will build up multiple tasks. The queue is based on the UUID so linking the UUID's will make one bit queue.