add nanoleaf service

This commit is contained in:
2022-08-20 23:48:52 +02:00
parent ca5dc75a1c
commit ae68679228
15 changed files with 1132 additions and 101 deletions
+38
View File
@@ -0,0 +1,38 @@
package events
import "fmt"
type ButtonPressed struct {
ID string `json:"id"`
SwipedID string `json:"swipedId,omitempty"`
Name string `json:"name"`
}
func (e ButtonPressed) EventDescription() string {
if e.SwipedID != "" {
return fmt.Sprintf("ButtonPressed(name:%s, swipe:%s->%s)", e.Name, e.SwipedID, e.ID)
} else {
return fmt.Sprintf("ButtonPressed(name:%s, id:%s)", e.Name, e.ID)
}
}
func (e ButtonPressed) TriggerKind() string {
return "ButtonPressed:" + e.Name
}
func (e ButtonPressed) TriggerValue(key string) (string, bool) {
switch key {
case "name":
return e.Name, true
case "id":
return e.ID, true
case "swipedFromId", "swipedId":
if e.SwipedID != "" {
return e.SwipedID, true
} else {
return "", false
}
default:
return "", false
}
}
-20
View File
@@ -1,20 +0,0 @@
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)
}
+76 -6
View File
@@ -5,6 +5,23 @@ import (
"git.aiterp.net/lucifer3/server/device"
)
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"`
@@ -14,16 +31,69 @@ type HardwareState struct {
State device.State `json:"state"`
}
func (d HardwareState) EventDescription() string {
func (e HardwareState) EventDescription() string {
return fmt.Sprintf("HardwareState(id:%s, iname:%#+v, sflags:%s, cflags:%s, buttons:%v, state:%s)",
d.ID, d.InternalName, d.SupportFlags, d.ColorFlags, d.Buttons, d.State,
e.ID, e.InternalName, e.SupportFlags, e.ColorFlags, e.Buttons, e.State,
)
}
type Unreachable struct {
DeviceID string `json:"deviceId"`
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 (d Unreachable) EventDescription() string {
return fmt.Sprintf("Unreachable(id:%s)", d.DeviceID)
func (e HardwareMetadata) EventDescription() string {
return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
}
// DevicesReady is triggered to indicate that all hardware states have been pushed to the bus ahead of this event.
type DevicesReady struct {
ID string `json:"id"`
}
func (d DevicesReady) EventDescription() string {
return fmt.Sprintf("DevicesReady(id:%s)", d.ID)
}
type DevicesUnreachable struct {
ID string `json:"id"`
}
func (d DevicesUnreachable) EventDescription() string {
return fmt.Sprintf("DevicesUnreachable(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 DeviceAvailable struct {
ID string
Name string
}
func (e DeviceAvailable) EventDescription() string {
return fmt.Sprintf("DeviceAvailable(id:%s, name:%s)")
}
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)
}