package events import ( "fmt" "git.aiterp.net/lucifer3/server/device" "git.aiterp.net/lucifer3/server/internal/color" "git.aiterp.net/lucifer3/server/internal/formattools" "os" ) type DeviceConnected struct { Prefix string `json:"prefix"` } func (e DeviceConnected) EventDescription() string { return fmt.Sprintf("DeviceConnected(prefix:%s)", e.Prefix) } type DeviceDisconnected struct { Prefix string `json:"prefix"` Reason string `json:"reason"` } func (e DeviceDisconnected) EventDescription() string { return fmt.Sprintf("DeviceDisconnected(prefix:%s, reason:%s)", e.Prefix, e.Reason) } type HardwareState struct { ID string `json:"id"` InternalName string `json:"internalName"` SupportFlags device.SupportFlags `json:"supportFlags"` ColorFlags device.ColorFlags `json:"colorFlags"` ColorGamut *color.Gamut `json:"colorGamut,omitempty"` ColorKelvinRange *[2]int `json:"colorKelvinRange,omitempty"` Buttons []string `json:"buttons"` State device.State `json:"state"` BatteryPercentage *int `json:"batteryPercentage"` Unreachable bool `json:"unreachable"` Stale bool `json:"stale,omitempty"` } func (e HardwareState) EventDescription() string { return fmt.Sprintf("HardwareState(id:%s, iname:%#+v, sflags:%s, cflags:%s, buttons:%v, state:%s, unreachable:%t)", e.ID, e.InternalName, e.SupportFlags, e.ColorFlags, e.Buttons, e.State, e.Unreachable, ) } func (e HardwareState) VerboseKey() string { return "HardwareState" } // HardwareMetadata contains things that has no bearing on the functionality of // lucifer, but may be interesting to have in the GUI. type HardwareMetadata struct { ID string `json:"id"` X int `json:"x,omitempty"` Y int `json:"y,omitempty"` O int `json:"o,omitempty"` ShapeType string `json:"shapeType,omitempty"` Icon string `json:"icon,omitempty"` SerialNumber string `json:"serialNumber,omitempty"` FirmwareVersion string `json:"firmwareVersion,omitempty"` Stale bool `json:"stale,omitempty"` } func (e HardwareMetadata) EventDescription() string { return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon) } func (e HardwareMetadata) VerboseKey() string { return "HardwareMetadata" } // DeviceReady is triggered to indicate that set-state commands will be heeded for the device // by this ID. It may be unavailable, however. type DeviceReady struct { ID string `json:"id"` } func (d DeviceReady) EventDescription() string { return fmt.Sprintf("DeviceReady(id:%s)", d.ID) } type DeviceFailed struct { ID string `json:"id"` Error string `json:"error"` } func (e DeviceFailed) EventDescription() string { return fmt.Sprintf("DeviceFailed(id:%s, err:%s)", e.ID, e.Error) } type DeviceAccepted struct { ID string `json:"id"` APIKey string `json:"apiKey"` Extras map[string]string `json:"extras"` } func (e DeviceAccepted) EventDescription() string { if os.Getenv("DEV_SHOW_API_KEYS") == "true" { return fmt.Sprintf("DeviceAccepted(id:%s, apiKey:%s)", e.ID, e.APIKey) } else { return fmt.Sprintf("DeviceAccepted(id:%s, apiKey:%s)", e.ID, formattools.Asterisks(e.APIKey)) } } type DeviceForgotten struct { ID string `json:"id"` } func (e DeviceForgotten) EventDescription() string { return fmt.Sprintf("DeviceForgotten(id:%s)", e.ID) }