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.

48 lines
981 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package commands
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "strings"
  6. )
  7. type SetState struct {
  8. ID string
  9. State device.State
  10. }
  11. func (c SetState) Matches(driver string) (sub string, ok bool) {
  12. if strings.HasPrefix(c.ID, driver) && strings.HasPrefix(c.ID[len(driver):], ":") {
  13. return strings.SplitN(c.ID[len(driver)+1:], ":", 2)[0], true
  14. } else {
  15. return "", false
  16. }
  17. }
  18. func (c SetState) CommandDescription() string {
  19. return fmt.Sprintf("SetState(%s, %s)", c.ID, c.State)
  20. }
  21. func (c SetState) VerboseKey() string {
  22. return "SetState"
  23. }
  24. type SetStateBatch map[string]device.State
  25. func (c SetStateBatch) CommandDescription() string {
  26. b := strings.Builder{}
  27. b.WriteByte('\n')
  28. for key, value := range c {
  29. b.WriteString(" ")
  30. b.WriteString(key)
  31. b.WriteString(": ")
  32. b.WriteString(value.String())
  33. b.WriteRune('\n')
  34. }
  35. return fmt.Sprintf("SetStateBatch(%s)", b.String())
  36. }
  37. func (c SetStateBatch) VerboseKey() string {
  38. return "SetStateBatch"
  39. }