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.

51 lines
1.8 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. "github.com/google/uuid"
  8. )
  9. type Patch struct {
  10. Assignment *AssignmentPatch `json:"assignment,omitempty"`
  11. Device *DevicePatch `json:"device,omitempty"`
  12. }
  13. func (e Patch) EventDescription() string {
  14. if e.Device != nil {
  15. switch {
  16. case e.Device.DesiredState != nil:
  17. return fmt.Sprintf("uistate.Patch(device=%s, desired state)", e.Device.ID)
  18. default:
  19. return fmt.Sprintf("uistate.Patch(device=%s)", e.Device.ID)
  20. }
  21. } else if e.Assignment != nil {
  22. return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
  23. } else {
  24. return "uistate.Patch"
  25. }
  26. }
  27. type DevicePatch struct {
  28. ID string `json:"id,omitempty"`
  29. Name *string `json:"name,omitempty"`
  30. HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"`
  31. HWState *events.HardwareState `json:"hwState,omitempty"`
  32. DesiredState *device.State `json:"desiredState,omitempty"`
  33. SetAliases []string `json:"setAliases,omitempty"`
  34. AddAlias *string `json:"addAlias,omitempty"`
  35. RemoveAlias *string `json:"removeAlias,omitempty"`
  36. Assignment *uuid.UUID `json:"assignment,omitempty"`
  37. ClearAssignment bool `json:"clearAssignment,omitempty"`
  38. Delete bool `json:"delete,omitempty"`
  39. }
  40. type AssignmentPatch struct {
  41. ID uuid.UUID `json:"id"`
  42. AddDeviceID *string `json:"addDeviceId"`
  43. RemoveDeviceID *string `json:"removeDeviceId"`
  44. Effect *effects.Serializable `json:"effect"`
  45. Delete bool `json:"delete"`
  46. }