diff --git a/bus.go b/bus.go index 5003a92..b7ee0de 100644 --- a/bus.go +++ b/bus.go @@ -11,6 +11,14 @@ type Event interface { 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 { CommandDescription() string } diff --git a/cmd/bustest/main.go b/cmd/bustest/main.go index ebf96ef..36ecb63 100644 --- a/cmd/bustest/main.go +++ b/cmd/bustest/main.go @@ -61,6 +61,17 @@ func main() { 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) log.Println("Search \"**:Hexagon {1,5,6}\"") diff --git a/events/external.go b/events/external.go new file mode 100644 index 0000000..0fbb0c8 --- /dev/null +++ b/events/external.go @@ -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 +}