add sensor handling.
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,10 @@ func (e HardwareState) EventDescription() string {
|
||||
)
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -63,6 +67,10 @@ 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 {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package events
|
||||
|
||||
import "fmt"
|
||||
|
||||
type TemperatureChanged struct {
|
||||
ID string
|
||||
Temperature float64
|
||||
}
|
||||
|
||||
func (e TemperatureChanged) TriggerKind() string {
|
||||
return "TemperatureChanged"
|
||||
}
|
||||
|
||||
func (e TemperatureChanged) TriggerValue(key string) (string, bool) {
|
||||
switch key {
|
||||
case "temperature":
|
||||
return fmt.Sprintf("%.2f", e.Temperature), true
|
||||
case "id":
|
||||
return e.ID, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func (e TemperatureChanged) EventDescription() string {
|
||||
return fmt.Sprintf("TemperatureChanged(id=%s, temperature=%.2f)", e.ID, e.Temperature)
|
||||
}
|
||||
|
||||
type MotionSensed struct {
|
||||
ID string
|
||||
SecondsSince float64
|
||||
}
|
||||
|
||||
func (e MotionSensed) TriggerKind() string {
|
||||
return "MotionSensed"
|
||||
}
|
||||
|
||||
func (e MotionSensed) TriggerValue(key string) (string, bool) {
|
||||
switch key {
|
||||
case "secondsSince":
|
||||
return fmt.Sprintf("%.1f", e.SecondsSince), true
|
||||
case "id":
|
||||
return e.ID, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func (e MotionSensed) EventDescription() string {
|
||||
return fmt.Sprintf("MotionSensed(id=%s, secondsSince=%.2f)", e.ID, e.SecondsSince)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user