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

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