package uistate import ( "fmt" "git.aiterp.net/lucifer3/server/device" "git.aiterp.net/lucifer3/server/effects" "git.aiterp.net/lucifer3/server/events" "git.aiterp.net/lucifer3/server/internal/color" "git.aiterp.net/lucifer3/server/services/script" "github.com/google/uuid" ) type Patch struct { Assignment *AssignmentPatch `json:"assignment,omitempty"` Device *DevicePatch `json:"device,omitempty"` Script *ScriptPatch `json:"script,omitempty"` } func (e Patch) VerboseKey() string { return "uistate.Patch" } func (e Patch) EventDescription() string { if e.Device != nil { switch { case e.Device.Name != nil: return fmt.Sprintf("uistate.Patch(device=%s, name=%s)", e.Device.ID, *e.Device.Name) case e.Device.DesiredState != nil: return fmt.Sprintf("uistate.Patch(device=%s, desiredState=%s)", e.Device.ID, e.Device.DesiredState.String()) case e.Device.HWState != nil: return fmt.Sprintf("uistate.Patch(device=%s, hwState)", e.Device.ID) case e.Device.HWMetadata != nil: return fmt.Sprintf("uistate.Patch(device=%s, hwMetadata)", e.Device.ID) case e.Device.AddAlias != nil: return fmt.Sprintf("uistate.Patch(device=%s, addAlias=%s)", e.Device.ID, *e.Device.AddAlias) case e.Device.RemoveAlias != nil: return fmt.Sprintf("uistate.Patch(device=%s, removeAlias=%s)", e.Device.ID, *e.Device.RemoveAlias) case e.Device.ActiveColorRGB != nil: col := color.Color{RGB: e.Device.ActiveColorRGB} return fmt.Sprintf("uistate.Patch(device=%s, activeColorRgb=%s)", e.Device.ID, col.String()) default: return fmt.Sprintf("uistate.Patch(device=%s, ...other)", e.Device.ID) } } else if e.Assignment != nil { return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID) } else if e.Script != nil { return fmt.Sprintf("uistate.Patch(script=%s)", e.Script.Name) } else { return "uistate.Patch" } } type DevicePatch struct { ID string `json:"id,omitempty"` Name *string `json:"name,omitempty"` HWMetadata *events.HardwareMetadata `json:"hwMetadata,omitempty"` HWState *events.HardwareState `json:"hwState,omitempty"` DesiredState *device.State `json:"desiredState,omitempty"` SetAliases []string `json:"setAliases,omitempty"` AddAlias *string `json:"addAlias,omitempty"` RemoveAlias *string `json:"removeAlias,omitempty"` Assignment *uuid.UUID `json:"assignment,omitempty"` ClearAssignment bool `json:"clearAssignment,omitempty"` ActiveColorRGB *color.RGB `json:"activeColorRgb,omitempty"` ClearActiveColorRGB bool `json:"clearActiveColorRGB,omitempty"` Sensors *DeviceSensors `json:"sensors,omitempty"` Delete bool `json:"delete,omitempty"` } type AssignmentPatch struct { ID uuid.UUID `json:"id"` AddDeviceID *string `json:"addDeviceId,omitempty"` RemoveDeviceID *string `json:"removeDeviceId,omitempty"` Effect *effects.Serializable `json:"effect,omitempty"` Variables map[string]float64 `json:"variables,omitempty"` Delete bool `json:"delete,omitempty"` } type ScriptPatch struct { Name string Lines []script.Line }