You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.3 KiB
59 lines
1.3 KiB
package script
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/google/uuid"
|
|
"strings"
|
|
)
|
|
|
|
type UpdateTrigger Trigger
|
|
|
|
func (c UpdateTrigger) CommandDescription() string {
|
|
return fmt.Sprintf("script.UpdateTrigger(%s, %s(%#+v, %#+v))",
|
|
c.ID, c.Event, c.DeviceMatch, c.Parameter,
|
|
)
|
|
}
|
|
|
|
type DeleteTrigger struct {
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (c DeleteTrigger) CommandDescription() string {
|
|
return fmt.Sprintf("script.DeleteTrigger(%s)", c.ID)
|
|
}
|
|
|
|
type SetVariable struct {
|
|
Match *string
|
|
Devices []string
|
|
Key string
|
|
Value string
|
|
}
|
|
|
|
func (c SetVariable) CommandDescription() string {
|
|
switch {
|
|
case c.Match != nil:
|
|
return fmt.Sprintf("script.SetVariable(tag(%s), %s, %s)", *c.Match, c.Key, c.Value)
|
|
case c.Devices != nil:
|
|
return fmt.Sprintf("script.SetVariable(devices(%s), %s, %s)", strings.Join(c.Devices, ", "), c.Key, c.Value)
|
|
default:
|
|
return fmt.Sprintf("script.SetVariable(global, %s, %s)", c.Key, c.Value)
|
|
}
|
|
}
|
|
|
|
type Update struct {
|
|
Name string `json:"name"`
|
|
Lines []Line `json:"lines"`
|
|
}
|
|
|
|
func (c Update) CommandDescription() string {
|
|
return fmt.Sprintf("script.Update(%s, [%d lines...])", c.Name, len(c.Lines))
|
|
}
|
|
|
|
type Execute struct {
|
|
Name string `json:"name"`
|
|
Match string `json:"match"`
|
|
}
|
|
|
|
func (c Execute) CommandDescription() string {
|
|
return fmt.Sprintf("script.Execute(%s, %s)", c.Name, c.Match)
|
|
}
|