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.
86 lines
1.8 KiB
86 lines
1.8 KiB
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
|
|
}
|
|
}
|