more tinkering.

This commit is contained in:
2022-08-14 13:57:56 +02:00
parent e752b1bafd
commit 15a4f3289f
16 changed files with 331 additions and 237 deletions
+20
View File
@@ -0,0 +1,20 @@
package events
import "fmt"
type Connected struct {
Prefix string `json:"prefix"`
}
func (e Connected) EventDescription() string {
return fmt.Sprintf("Connect(prefix:%s)", e.Prefix)
}
type Disconnected struct {
Prefix string `json:"prefix"`
Reason string `json:"reason"`
}
func (e Disconnected) EventDescription() string {
return fmt.Sprintf("Disconnected(prefix:%s, reason:%s)", e.Prefix, e.Reason)
}
+12 -73
View File
@@ -3,86 +3,25 @@ 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"`
type HardwareState struct {
DeviceID string `json:"internalId"`
SupportFlags 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,
func (d HardwareState) EventDescription() string {
return fmt.Sprintf("HardwareState(id:%s, sflags:%s, cflags:%s, state:%s)",
d.DeviceID, d.SupportFlags, 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"`
type Unreachable struct {
DeviceID string `json:"deviceId"`
}
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,
)
func (d Unreachable) EventDescription() string {
return fmt.Sprintf("Unreachable(id:%s)", d.DeviceID)
}
-17
View File
@@ -1,17 +0,0 @@
package events
import "fmt"
type HubConnected struct{}
func (c HubConnected) EventName() string {
return "HubConnected"
}
type HubDisconnected struct {
Reason string
}
func (d HubDisconnected) EventName() string {
return fmt.Sprintf("HubDisconnected(reason:%s)", d.Reason)
}