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.

91 lines
3.6 KiB

1 year ago
1 year ago
  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/script"
  9. "github.com/google/uuid"
  10. )
  11. type Patch struct {
  12. Assignment *AssignmentPatch `json:"assignment,omitempty"`
  13. Device *DevicePatch `json:"device,omitempty"`
  14. Script *ScriptPatch `json:"script,omitempty"`
  15. Trigger *TriggerPatch `json:"trigger,omitempty"`
  16. }
  17. func (e Patch) VerboseKey() string {
  18. return "uistate.Patch"
  19. }
  20. func (e Patch) EventDescription() string {
  21. if e.Device != nil {
  22. switch {
  23. case e.Device.Name != nil:
  24. return fmt.Sprintf("uistate.Patch(device=%s, name=%s)", e.Device.ID, *e.Device.Name)
  25. case e.Device.DesiredState != nil:
  26. return fmt.Sprintf("uistate.Patch(device=%s, desiredState=%s)", e.Device.ID, e.Device.DesiredState.String())
  27. case e.Device.HWState != nil:
  28. return fmt.Sprintf("uistate.Patch(device=%s, hwState)", e.Device.ID)
  29. case e.Device.HWMetadata != nil:
  30. return fmt.Sprintf("uistate.Patch(device=%s, hwMetadata)", e.Device.ID)
  31. case e.Device.AddAlias != nil:
  32. return fmt.Sprintf("uistate.Patch(device=%s, addAlias)", e.Device.ID)
  33. case e.Device.RemoveAlias != nil:
  34. return fmt.Sprintf("uistate.Patch(device=%s, removeAlias)", e.Device.ID)
  35. case e.Device.ActiveColorRGB != nil:
  36. col := color.Color{RGB: e.Device.ActiveColorRGB}
  37. return fmt.Sprintf("uistate.Patch(device=%s, activeColorRgb=%s)", e.Device.ID, col.String())
  38. case e.Device.DesiredColorRGB != nil:
  39. col := color.Color{RGB: e.Device.DesiredColorRGB}
  40. return fmt.Sprintf("uistate.Patch(device=%s, desiredColorRgb=%s)", e.Device.ID, col.String())
  41. default:
  42. return fmt.Sprintf("uistate.Patch(device=%s, ...other)", e.Device.ID)
  43. }
  44. } else if e.Assignment != nil {
  45. return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
  46. } else if e.Script != nil {
  47. return fmt.Sprintf("uistate.Patch(script=%s)", e.Script.Name)
  48. } else {
  49. return "uistate.Patch"
  50. }
  51. }
  52. type DevicePatch struct {
  53. ID string `json:"id,omitempty"`
  54. Name *string `json:"name,omitempty"`
  55. HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"`
  56. HWState *events.HardwareState `json:"hwState,omitempty"`
  57. DesiredState *device.State `json:"desiredState,omitempty"`
  58. AddAlias *string `json:"addAlias,omitempty"`
  59. RemoveAlias *string `json:"removeAlias,omitempty"`
  60. Assignment *uuid.UUID `json:"assignment,omitempty"`
  61. ClearAssignment bool `json:"clearAssignment,omitempty"`
  62. DesiredColorRGB *color.RGB `json:"desiredColorRgb,omitempty"`
  63. ActiveColorRGB *color.RGB `json:"activeColorRgb,omitempty"`
  64. ClearActiveColorRGB bool `json:"clearActiveColorRGB,omitempty"`
  65. Sensors *DeviceSensors `json:"sensors,omitempty"`
  66. Delete bool `json:"delete,omitempty"`
  67. }
  68. type AssignmentPatch struct {
  69. ID uuid.UUID `json:"id"`
  70. AddDeviceID *string `json:"addDeviceId,omitempty"`
  71. RemoveDeviceID *string `json:"removeDeviceId,omitempty"`
  72. Effect *effects.Serializable `json:"effect,omitempty"`
  73. Variables map[string]float64 `json:"variables,omitempty"`
  74. Delete bool `json:"delete,omitempty"`
  75. }
  76. type ScriptPatch struct {
  77. Name string
  78. Lines []script.Line
  79. }
  80. type TriggerPatch struct {
  81. script.Trigger
  82. Delete bool `json:"delete,omitempty"`
  83. }