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.

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