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.

88 lines
3.5 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.DesiredState != nil:
  24. return fmt.Sprintf("uistate.Patch(device=%s, desiredState=%s)", e.Device.ID, e.Device.DesiredState.String())
  25. case e.Device.HWState != nil:
  26. return fmt.Sprintf("uistate.Patch(device=%s, hwState)", e.Device.ID)
  27. case e.Device.HWMetadata != nil:
  28. return fmt.Sprintf("uistate.Patch(device=%s, hwMetadata)", e.Device.ID)
  29. case e.Device.AddAlias != nil:
  30. return fmt.Sprintf("uistate.Patch(device=%s, addAlias)", e.Device.ID)
  31. case e.Device.RemoveAlias != nil:
  32. return fmt.Sprintf("uistate.Patch(device=%s, removeAlias)", e.Device.ID)
  33. case e.Device.ActiveColorRGB != nil:
  34. col := color.Color{RGB: e.Device.ActiveColorRGB}
  35. return fmt.Sprintf("uistate.Patch(device=%s, activeColorRgb=%s)", e.Device.ID, col.String())
  36. case e.Device.DesiredColorRGB != nil:
  37. col := color.Color{RGB: e.Device.DesiredColorRGB}
  38. return fmt.Sprintf("uistate.Patch(device=%s, desiredColorRgb=%s)", e.Device.ID, col.String())
  39. default:
  40. return fmt.Sprintf("uistate.Patch(device=%s, ...other)", e.Device.ID)
  41. }
  42. } else if e.Assignment != nil {
  43. return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
  44. } else if e.Script != nil {
  45. return fmt.Sprintf("uistate.Patch(script=%s)", e.Script.Name)
  46. } else {
  47. return "uistate.Patch"
  48. }
  49. }
  50. type DevicePatch struct {
  51. ID string `json:"id,omitempty"`
  52. HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"`
  53. HWState *events.HardwareState `json:"hwState,omitempty"`
  54. DesiredState *device.State `json:"desiredState,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. DesiredColorRGB *color.RGB `json:"desiredColorRgb,omitempty"`
  60. ActiveColorRGB *color.RGB `json:"activeColorRgb,omitempty"`
  61. ClearActiveColorRGB bool `json:"clearActiveColorRGB,omitempty"`
  62. Sensors *DeviceSensors `json:"sensors,omitempty"`
  63. Delete bool `json:"delete,omitempty"`
  64. }
  65. type AssignmentPatch struct {
  66. ID uuid.UUID `json:"id"`
  67. AddDeviceID *string `json:"addDeviceId,omitempty"`
  68. RemoveDeviceID *string `json:"removeDeviceId,omitempty"`
  69. Effect *effects.Serializable `json:"effect,omitempty"`
  70. Variables map[string]float64 `json:"variables,omitempty"`
  71. Delete bool `json:"delete,omitempty"`
  72. }
  73. type ScriptPatch struct {
  74. Name string
  75. Lines []script.Line
  76. }
  77. type TriggerPatch struct {
  78. script.Trigger
  79. Delete bool `json:"delete,omitempty"`
  80. }