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.
 
 
 
 
 
 

90 lines
2.9 KiB

package events
import (
"fmt"
"git.aiterp.net/lucifer3/server/device"
"git.aiterp.net/lucifer3/server/internal/color"
)
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:"internalId"`
InternalName string `json:"internalName"`
SupportFlags device.SupportFlags `json:"supportFlags"`
ColorFlags device.ColorFlags `json:"colorFlags"`
ColorGamut *color.Gamut `json:"colorGamut,omitempty"`
TemperatureRange *[2]int `json:"temperatureRange,omitempty"`
Buttons []string `json:"buttons"`
State device.State `json:"state"`
BatteryPercentage *int `json:"batteryPercentage"`
Unreachable bool `json:"unreachable"`
}
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,
)
}
// 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"`
}
func (e HardwareMetadata) EventDescription() string {
return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
}
// 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 {
// TODO: Use formattools.Asterisks
return fmt.Sprintf("DeviceAccepted(id:%s, apiKey:%s)", e.ID, e.APIKey)
}