package events import ( "fmt" "git.aiterp.net/lucifer3/server/device" "git.aiterp.net/lucifer3/server/internal/gentools" "strings" ) type DeviceHardwareStateChange struct { ID int64 `json:"id,omitempty"` InternalID string `json:"internalId"` DeviceFlags device.SupportFlags `json:"deviceFlags"` ColorFlags device.ColorFlag `json:"colorFlags"` State device.State `json:"state"` } func (d DeviceHardwareStateChange) EventName() string { idStr := "" if d.ID != 0 { idStr = fmt.Sprintf("id:%d, ", d.ID) } return fmt.Sprintf("DeviceHardwareStateChange(%siid:%s, dflags:%d, cflags:%d, state:%s)", idStr, d.InternalID, d.DeviceFlags, d.ColorFlags, d.State, ) } // DeviceRegister must be sent directly to the device hub that took it. type DeviceRegister struct { ID int64 `json:"id"` InternalID string `json:"internalId"` } func (d DeviceRegister) EventName() string { return fmt.Sprintf("DeviceRegister(id:%d, iid:%s)", d.ID, d.InternalID) } type DeviceDesiredStateChange struct { ID int64 `json:"id"` NewState device.State `json:"newState"` } func (d DeviceDesiredStateChange) EventName() string { return fmt.Sprintf("DeviceDesiredStateChange(id:%d, state:%s)", d.ID, d.NewState, ) } type DeviceAssignment struct { IDs []int64 `json:"ids"` Version int64 `json:"version"` // DeviceManager sets the version. State *device.State `json:"state"` // DeviceManager sets the state in a follow-up event. Others still need to see it to kick the device. Effect *int64 `json:"effect"` // An effect will pick this up. A scene may defer to own effects Scene *int64 `json:"scene"` // A scene will take it and handle it. Might move it out a level so scenes are just filters that create assignments } func (d DeviceAssignment) EventName() string { s := "(!!no change!!)" switch { case d.State != nil: s = fmt.Sprintf("state:%s", *d.State) case d.Effect != nil: s = fmt.Sprintf("effect:%d", *d.Effect) case d.Scene != nil: s = fmt.Sprintf("scene:%d", *d.Scene) } return fmt.Sprintf("DeviceAssignment(ids:%s, version:%d, %s)", strings.Join(gentools.FmtSprintArray(d.IDs), ","), d.Version, s, ) } // DeviceRestore attempts to restore devices to a previous version. It may not be // successful. type DeviceRestore struct { IDs []int64 `json:"ids"` Version int64 `json:"version"` } func (d DeviceRestore) EventName() string { return fmt.Sprintf("DeviceRestore(ids:%s, version:%d)", strings.Join(gentools.FmtSprintArray(d.IDs), ","), d.Version, ) }