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.

90 lines
2.9 KiB

2 years ago
2 years ago
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. "git.aiterp.net/lucifer3/server/internal/color"
  6. )
  7. type DeviceConnected struct {
  8. Prefix string `json:"prefix"`
  9. }
  10. func (e DeviceConnected) EventDescription() string {
  11. return fmt.Sprintf("DeviceConnected(prefix:%s)", e.Prefix)
  12. }
  13. type DeviceDisconnected struct {
  14. Prefix string `json:"prefix"`
  15. Reason string `json:"reason"`
  16. }
  17. func (e DeviceDisconnected) EventDescription() string {
  18. return fmt.Sprintf("DeviceDisconnected(prefix:%s, reason:%s)", e.Prefix, e.Reason)
  19. }
  20. type HardwareState struct {
  21. ID string `json:"internalId"`
  22. InternalName string `json:"internalName"`
  23. SupportFlags device.SupportFlags `json:"supportFlags"`
  24. ColorFlags device.ColorFlags `json:"colorFlags"`
  25. ColorGamut *color.Gamut `json:"colorGamut,omitempty"`
  26. ColorKelvinRange *[2]int `json:"colorKelvinRange,omitempty"`
  27. Buttons []string `json:"buttons"`
  28. State device.State `json:"state"`
  29. BatteryPercentage *int `json:"batteryPercentage"`
  30. Unreachable bool `json:"unreachable"`
  31. }
  32. func (e HardwareState) EventDescription() string {
  33. return fmt.Sprintf("HardwareState(id:%s, iname:%#+v, sflags:%s, cflags:%s, buttons:%v, state:%s, unreachable:%t)",
  34. e.ID, e.InternalName, e.SupportFlags, e.ColorFlags, e.Buttons, e.State, e.Unreachable,
  35. )
  36. }
  37. // HardwareMetadata contains things that has no bearing on the functionality of
  38. // lucifer, but may be interesting to have in the GUI.
  39. type HardwareMetadata struct {
  40. ID string `json:"id"`
  41. X int `json:"x,omitempty"`
  42. Y int `json:"y,omitempty"`
  43. O int `json:"o,omitempty"`
  44. ShapeType string `json:"shapeType,omitempty"`
  45. Icon string `json:"icon,omitempty"`
  46. SerialNumber string `json:"serialNumber,omitempty"`
  47. FirmwareVersion string `json:"firmwareVersion,omitempty"`
  48. }
  49. func (e HardwareMetadata) EventDescription() string {
  50. return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
  51. }
  52. // DeviceReady is triggered to indicate that set-state commands will be heeded for the device
  53. // by this ID. It may be unavailable, however.
  54. type DeviceReady struct {
  55. ID string `json:"id"`
  56. }
  57. func (d DeviceReady) EventDescription() string {
  58. return fmt.Sprintf("DeviceReady(id:%s)", d.ID)
  59. }
  60. type DeviceFailed struct {
  61. ID string `json:"id"`
  62. Error string `json:"error"`
  63. }
  64. func (e DeviceFailed) EventDescription() string {
  65. return fmt.Sprintf("DeviceFailed(id:%s, err:%s)", e.ID, e.Error)
  66. }
  67. type DeviceAccepted struct {
  68. ID string `json:"id"`
  69. APIKey string `json:"apiKey"`
  70. Extras map[string]string `json:"extras"`
  71. }
  72. func (e DeviceAccepted) EventDescription() string {
  73. // TODO: Use formattools.Asterisks
  74. return fmt.Sprintf("DeviceAccepted(id:%s, apiKey:%s)", e.ID, e.APIKey)
  75. }