add trigger event idea.
This commit is contained in:
@@ -11,6 +11,14 @@ type Event interface {
|
|||||||
EventDescription() string
|
EventDescription() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A TriggerEvent is a catch-all for events that may trigger a command from the event handler.
|
||||||
|
type TriggerEvent interface {
|
||||||
|
Event
|
||||||
|
|
||||||
|
TriggerKind() string
|
||||||
|
TriggerValue(key string) (string, bool)
|
||||||
|
}
|
||||||
|
|
||||||
type Command interface {
|
type Command interface {
|
||||||
CommandDescription() string
|
CommandDescription() string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,17 @@ func main() {
|
|||||||
SceneID: 7,
|
SceneID: 7,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
bus.RunEvent(events.ExternalEvent{
|
||||||
|
Kind: "weather",
|
||||||
|
Values: map[string]string{
|
||||||
|
"city": "Ørland",
|
||||||
|
"region": "Trøndelag",
|
||||||
|
"country": "Norway",
|
||||||
|
"temperature_celsius": "21.00",
|
||||||
|
"precipitation_mm": "3.21",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
time.Sleep(time.Second / 8)
|
time.Sleep(time.Second / 8)
|
||||||
|
|
||||||
log.Println("Search \"**:Hexagon {1,5,6}\"")
|
log.Println("Search \"**:Hexagon {1,5,6}\"")
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package events
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type ExternalEvent struct {
|
||||||
|
Kind string
|
||||||
|
Values map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ExternalEvent) EventDescription() string {
|
||||||
|
return fmt.Sprintf("External(kind:%s, values:%v)", e.Kind, e.Values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ExternalEvent) TriggerKind() string {
|
||||||
|
return fmt.Sprintf("external.%s", e.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ExternalEvent) TriggerValue(key string) (string, bool) {
|
||||||
|
v, ok := e.Values[key]
|
||||||
|
return v, ok
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user