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.

99 lines
2.7 KiB

2 years ago
2 years ago
2 years ago
  1. package events
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. )
  6. type DeviceConnected struct {
  7. Prefix string `json:"prefix"`
  8. }
  9. func (e DeviceConnected) EventDescription() string {
  10. return fmt.Sprintf("DeviceConnected(prefix:%s)", e.Prefix)
  11. }
  12. type DeviceDisconnected struct {
  13. Prefix string `json:"prefix"`
  14. Reason string `json:"reason"`
  15. }
  16. func (e DeviceDisconnected) EventDescription() string {
  17. return fmt.Sprintf("DeviceDisconnected(prefix:%s, reason:%s)", e.Prefix, e.Reason)
  18. }
  19. type HardwareState struct {
  20. ID string `json:"internalId"`
  21. InternalName string `json:"internalName"`
  22. SupportFlags device.SupportFlags `json:"deviceFlags"`
  23. ColorFlags device.ColorFlag `json:"colorFlags"`
  24. Buttons []string `json:"buttons"`
  25. State device.State `json:"state"`
  26. }
  27. func (e HardwareState) EventDescription() string {
  28. return fmt.Sprintf("HardwareState(id:%s, iname:%#+v, sflags:%s, cflags:%s, buttons:%v, state:%s)",
  29. e.ID, e.InternalName, e.SupportFlags, e.ColorFlags, e.Buttons, e.State,
  30. )
  31. }
  32. type HardwareMetadata struct {
  33. ID string `json:"id"`
  34. X int `json:"x,omitempty"`
  35. Y int `json:"y,omitempty"`
  36. O int `json:"o,omitempty"`
  37. ShapeType string `json:"shapeType,omitempty"`
  38. Icon string `json:"icon,omitempty"`
  39. SerialNumber string `json:"serialNumber,omitempty"`
  40. FirmwareVersion string `json:"firmwareVersion,omitempty"`
  41. }
  42. func (e HardwareMetadata) EventDescription() string {
  43. return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
  44. }
  45. // DevicesReady is triggered to indicate that all hardware states have been pushed to the bus ahead of this event.
  46. type DevicesReady struct {
  47. ID string `json:"id"`
  48. }
  49. func (d DevicesReady) EventDescription() string {
  50. return fmt.Sprintf("DevicesReady(id:%s)", d.ID)
  51. }
  52. type DevicesUnreachable struct {
  53. ID string `json:"id"`
  54. }
  55. func (d DevicesUnreachable) EventDescription() string {
  56. return fmt.Sprintf("DevicesUnreachable(id:%s)", d.ID)
  57. }
  58. type DeviceFailed struct {
  59. ID string `json:"id"`
  60. Error string `json:"error"`
  61. }
  62. func (e DeviceFailed) EventDescription() string {
  63. return fmt.Sprintf("DeviceFailed(id:%s, err:%s)", e.ID, e.Error)
  64. }
  65. type DeviceAvailable struct {
  66. ID string
  67. Name string
  68. }
  69. func (e DeviceAvailable) EventDescription() string {
  70. return fmt.Sprintf("DeviceAvailable(id:%s, name:%s)")
  71. }
  72. type DeviceAccepted struct {
  73. ID string `json:"id"`
  74. APIKey string `json:"apiKey"`
  75. Extras map[string]string `json:"extras"`
  76. }
  77. func (e DeviceAccepted) EventDescription() string {
  78. // TODO: Use formattools.Asterisks
  79. return fmt.Sprintf("DeviceAccepted(id:%s, apiKey:%s)", e.ID, e.APIKey)
  80. }