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.

84 lines
2.5 KiB

2 years ago
2 years ago
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. Unreachable bool `json:"unreachable"`
  27. }
  28. func (e HardwareState) EventDescription() string {
  29. return fmt.Sprintf("HardwareState(id:%s, iname:%#+v, sflags:%s, cflags:%s, buttons:%v, state:%s, unreachable:%t)",
  30. e.ID, e.InternalName, e.SupportFlags, e.ColorFlags, e.Buttons, e.State, e.Unreachable,
  31. )
  32. }
  33. type HardwareMetadata struct {
  34. ID string `json:"id"`
  35. X int `json:"x,omitempty"`
  36. Y int `json:"y,omitempty"`
  37. O int `json:"o,omitempty"`
  38. ShapeType string `json:"shapeType,omitempty"`
  39. Icon string `json:"icon,omitempty"`
  40. SerialNumber string `json:"serialNumber,omitempty"`
  41. FirmwareVersion string `json:"firmwareVersion,omitempty"`
  42. }
  43. func (e HardwareMetadata) EventDescription() string {
  44. return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
  45. }
  46. // DeviceReady is triggered to indicate that set-state commands will be heeded for the device
  47. // by this ID. It may be unavailable, however.
  48. type DeviceReady struct {
  49. ID string `json:"id"`
  50. }
  51. func (d DeviceReady) EventDescription() string {
  52. return fmt.Sprintf("DeviceReady(id:%s)", d.ID)
  53. }
  54. type DeviceFailed struct {
  55. ID string `json:"id"`
  56. Error string `json:"error"`
  57. }
  58. func (e DeviceFailed) EventDescription() string {
  59. return fmt.Sprintf("DeviceFailed(id:%s, err:%s)", e.ID, e.Error)
  60. }
  61. type DeviceAccepted struct {
  62. ID string `json:"id"`
  63. APIKey string `json:"apiKey"`
  64. Extras map[string]string `json:"extras"`
  65. }
  66. func (e DeviceAccepted) EventDescription() string {
  67. // TODO: Use formattools.Asterisks
  68. return fmt.Sprintf("DeviceAccepted(id:%s, apiKey:%s)", e.ID, e.APIKey)
  69. }