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.

86 lines
3.6 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/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. }
  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. case e.Device.DesiredColorRGB != nil:
  38. col := color.Color{RGB: e.Device.DesiredColorRGB}
  39. return fmt.Sprintf("uistate.Patch(device=%s, desiredColorRgb=%s)", e.Device.ID, col.String())
  40. default:
  41. return fmt.Sprintf("uistate.Patch(device=%s, ...other)", e.Device.ID)
  42. }
  43. } else if e.Assignment != nil {
  44. return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
  45. } else if e.Script != nil {
  46. return fmt.Sprintf("uistate.Patch(script=%s)", e.Script.Name)
  47. } else {
  48. return "uistate.Patch"
  49. }
  50. }
  51. type DevicePatch struct {
  52. ID string `json:"id,omitempty"`
  53. Name *string `json:"name,omitempty"`
  54. HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"`
  55. HWState *events.HardwareState `json:"hwState,omitempty"`
  56. DesiredState *device.State `json:"desiredState,omitempty"`
  57. SetAliases []string `json:"setAliases,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. }