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.

69 lines
1.4 KiB

2 years ago
  1. package commands
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/internal/formattools"
  5. "strings"
  6. )
  7. type PairDevice struct {
  8. ID string `json:"id"`
  9. APIKey string `json:"apiKey"`
  10. }
  11. func (c PairDevice) CommandDescription() string {
  12. return fmt.Sprintf("PairDevice(%s, %s)", c.ID, formattools.Asterisks(c.APIKey))
  13. }
  14. func (c PairDevice) Matches(driver string) (sub string, ok bool) {
  15. split := strings.SplitN(c.ID, ":", 2)
  16. if split[0] != driver {
  17. return "", false
  18. }
  19. return split[1], true
  20. }
  21. type ConnectDevice struct {
  22. ID string `json:"id"`
  23. APIKey string `json:"apiKey"`
  24. }
  25. func (c ConnectDevice) Matches(driver string) (sub string, ok bool) {
  26. split := strings.SplitN(c.ID, ":", 2)
  27. if split[0] != driver {
  28. return "", false
  29. }
  30. return split[1], true
  31. }
  32. func (c ConnectDevice) CommandDescription() string {
  33. return fmt.Sprintf("ConnectDevice(%s, %s)", c.ID, formattools.Asterisks(c.APIKey))
  34. }
  35. type SearchDevices struct {
  36. ID string `json:"id"`
  37. Hint string `json:"hint"`
  38. }
  39. func (c SearchDevices) Matches(driver string) (string, bool) {
  40. split := strings.SplitN(c.ID, ":", 2)
  41. if split[0] != driver {
  42. return "", false
  43. }
  44. return split[1], true
  45. }
  46. func (c SearchDevices) CommandDescription() string {
  47. return fmt.Sprintf("SearchDevices(%s, %#+v)", c.ID, c.Hint)
  48. }
  49. type ForgetDevice struct {
  50. ID string `json:"id"`
  51. }
  52. func (c ForgetDevice) CommandDescription() string {
  53. return fmt.Sprintf("ForgetDevice(%s)", c.ID)
  54. }