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.

42 lines
941 B

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 = "SensorPresenceStart"
  21. ENSensorPresenceEnded = "SensorPresenceEnd"
  22. )
  23. func BridgeConnectedEvent(bridge Bridge) Event {
  24. e := Event{Name: ENBridgeConnected}
  25. e.AddPayload("bridgeId", strconv.Itoa(bridge.ID))
  26. return e
  27. }
  28. func BridgeDisconnectedEvent(bridge Bridge) Event {
  29. e := Event{Name: ENBridgeDisconnected}
  30. e.AddPayload("bridgeId", strconv.Itoa(bridge.ID))
  31. return e
  32. }