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.

30 lines
659 B

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("SetStates(%s, %s)", c.ID, c.State)
  20. }
  21. type SetStateBatch map[string]device.State
  22. func (c SetStateBatch) CommandDescription() string {
  23. return fmt.Sprintf("SetStateBatch(%d devices)", len(c))
  24. }