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.

44 lines
1.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package models
  2. import "strconv"
  3. type Event struct {
  4. Name string `json:"name"`
  5. Payload map[string]string `json:"payload,omitempty"`
  6. }
  7. func (e *Event) AddPayload(key, value string) {
  8. if e.Payload == nil {
  9. e.Payload = make(map[string]string, 8)
  10. }
  11. e.Payload[key] = value
  12. }
  13. func (e *Event) HasPayload(key string) bool {
  14. return e.Payload != nil && e.Payload[key] != ""
  15. }
  16. var (
  17. ENBridgeConnected = "BridgeConnected"
  18. ENBridgeDisconnected = "BridgeDisconnected"
  19. ENButtonPressed = "ButtonPressed"
  20. ENSensorPresenceStarted = "SensorPresenceStarted"
  21. ENSensorPresenceEnding = "SensorPresenceEnding"
  22. ENSensorPresenceEnded = "SensorPresenceEnded"
  23. ENSensorTemperature = "SensorTemperature"
  24. )
  25. func BridgeConnectedEvent(bridge Bridge) Event {
  26. e := Event{Name: ENBridgeConnected}
  27. e.AddPayload("bridgeId", strconv.Itoa(bridge.ID))
  28. return e
  29. }
  30. func BridgeDisconnectedEvent(bridge Bridge) Event {
  31. e := Event{Name: ENBridgeDisconnected}
  32. e.AddPayload("bridgeId", strconv.Itoa(bridge.ID))
  33. return e
  34. }