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.

72 lines
3.0 KiB

  1. package uistate
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "git.aiterp.net/lucifer3/server/effects"
  6. "git.aiterp.net/lucifer3/server/events"
  7. "git.aiterp.net/lucifer3/server/internal/color"
  8. "github.com/google/uuid"
  9. )
  10. type Patch struct {
  11. Assignment *AssignmentPatch `json:"assignment,omitempty"`
  12. Device *DevicePatch `json:"device,omitempty"`
  13. }
  14. func (e Patch) VerboseKey() string {
  15. return "uistate.Patch"
  16. }
  17. func (e Patch) EventDescription() string {
  18. if e.Device != nil {
  19. switch {
  20. case e.Device.Name != nil:
  21. return fmt.Sprintf("uistate.Patch(device=%s, name=%s)", e.Device.ID, e.Device.Name)
  22. case e.Device.DesiredState != nil:
  23. return fmt.Sprintf("uistate.Patch(device=%s, desiredState=%s)", e.Device.ID, e.Device.DesiredState.String())
  24. case e.Device.HWState != nil:
  25. return fmt.Sprintf("uistate.Patch(device=%s, hwState)", e.Device.ID)
  26. case e.Device.HWMetadata != nil:
  27. return fmt.Sprintf("uistate.Patch(device=%s, hwMetadata)", e.Device.ID)
  28. case e.Device.AddAlias != nil:
  29. return fmt.Sprintf("uistate.Patch(device=%s, addAlias=%s)", e.Device.ID, *e.Device.AddAlias)
  30. case e.Device.RemoveAlias != nil:
  31. return fmt.Sprintf("uistate.Patch(device=%s, removeAlias=%s)", e.Device.ID, *e.Device.RemoveAlias)
  32. case e.Device.ActiveColorRGB != nil:
  33. col := color.Color{RGB: e.Device.ActiveColorRGB}
  34. return fmt.Sprintf("uistate.Patch(device=%s, activeColorRgb=%s)", e.Device.ID, col.String())
  35. default:
  36. return fmt.Sprintf("uistate.Patch(device=%s, ...other)", e.Device.ID)
  37. }
  38. } else if e.Assignment != nil {
  39. return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
  40. } else {
  41. return "uistate.Patch"
  42. }
  43. }
  44. type DevicePatch struct {
  45. ID string `json:"id,omitempty"`
  46. Name *string `json:"name,omitempty"`
  47. HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"`
  48. HWState *events.HardwareState `json:"hwState,omitempty"`
  49. DesiredState *device.State `json:"desiredState,omitempty"`
  50. SetAliases []string `json:"setAliases,omitempty"`
  51. AddAlias *string `json:"addAlias,omitempty"`
  52. RemoveAlias *string `json:"removeAlias,omitempty"`
  53. Assignment *uuid.UUID `json:"assignment,omitempty"`
  54. ClearAssignment bool `json:"clearAssignment,omitempty"`
  55. ActiveColorRGB *color.RGB `json:"activeColorRgb,omitempty"`
  56. ClearActiveColorRGB bool `json:"clearActiveColorRGB,omitempty"`
  57. Sensors *DeviceSensors `json:"sensors,omitempty"`
  58. Delete bool `json:"delete,omitempty"`
  59. }
  60. type AssignmentPatch struct {
  61. ID uuid.UUID `json:"id"`
  62. AddDeviceID *string `json:"addDeviceId"`
  63. RemoveDeviceID *string `json:"removeDeviceId"`
  64. Effect *effects.Serializable `json:"effect"`
  65. Delete bool `json:"delete"`
  66. }