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

  1. package script
  2. import (
  3. "fmt"
  4. "github.com/google/uuid"
  5. "strings"
  6. )
  7. type UpdateTrigger Trigger
  8. func (c UpdateTrigger) CommandDescription() string {
  9. return fmt.Sprintf("script.UpdateTrigger(%s, %s(%#+v, %#+v))",
  10. c.ID, c.Event, c.DeviceMatch, c.Parameter,
  11. )
  12. }
  13. type DeleteTrigger struct {
  14. ID uuid.UUID `json:"id"`
  15. }
  16. func (c DeleteTrigger) CommandDescription() string {
  17. return fmt.Sprintf("script.DeleteTrigger(%s)", c.ID)
  18. }
  19. type SetVariable struct {
  20. Match *string
  21. Devices []string
  22. Key string
  23. Value string
  24. }
  25. func (c SetVariable) CommandDescription() string {
  26. switch {
  27. case c.Match != nil:
  28. return fmt.Sprintf("script.SetVariable(tag(%s), %s, %s)", *c.Match, c.Key, c.Value)
  29. case c.Devices != nil:
  30. return fmt.Sprintf("script.SetVariable(devices(%s), %s, %s)", strings.Join(c.Devices, ", "), c.Key, c.Value)
  31. default:
  32. return fmt.Sprintf("script.SetVariable(global, %s, %s)", c.Key, c.Value)
  33. }
  34. }
  35. type Update struct {
  36. Name string `json:"name"`
  37. Lines []Line `json:"lines"`
  38. }
  39. func (c Update) CommandDescription() string {
  40. return fmt.Sprintf("script.Update(%s, [%d lines...])", c.Name, len(c.Lines))
  41. }
  42. type Execute struct {
  43. Name string `json:"name"`
  44. Match string `json:"match"`
  45. }
  46. func (c Execute) CommandDescription() string {
  47. return fmt.Sprintf("script.Execute(%s, %s)", c.Name, c.Match)
  48. }