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.
43 lines
992 B
43 lines
992 B
package models
|
|
|
|
import "strconv"
|
|
|
|
type Event struct {
|
|
Name string `json:"name"`
|
|
Payload map[string]string `json:"payload,omitempty"`
|
|
}
|
|
|
|
func (e *Event) AddPayload(key, value string) {
|
|
if e.Payload == nil {
|
|
e.Payload = make(map[string]string, 8)
|
|
}
|
|
|
|
e.Payload[key] = value
|
|
}
|
|
|
|
func (e *Event) HasPayload(key string) bool {
|
|
return e.Payload != nil && e.Payload[key] != ""
|
|
}
|
|
|
|
var (
|
|
ENBridgeConnected = "BridgeConnected"
|
|
ENBridgeDisconnected = "BridgeDisconnected"
|
|
ENButtonPressed = "ButtonPressed"
|
|
ENSensorPresenceStarted = "SensorPresenceStarted"
|
|
ENSensorPresenceEnded = "SensorPresenceEnded"
|
|
ENSensorTemperature = "SensorTemperature"
|
|
)
|
|
|
|
func BridgeConnectedEvent(bridge Bridge) Event {
|
|
e := Event{Name: ENBridgeConnected}
|
|
e.AddPayload("bridgeId", strconv.Itoa(bridge.ID))
|
|
|
|
return e
|
|
}
|
|
|
|
func BridgeDisconnectedEvent(bridge Bridge) Event {
|
|
e := Event{Name: ENBridgeDisconnected}
|
|
e.AddPayload("bridgeId", strconv.Itoa(bridge.ID))
|
|
|
|
return e
|
|
}
|