-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.go
100 lines (81 loc) · 2.88 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package wbgong
import "fmt"
// StartEvent represents start event
type StartEvent struct{}
func (e StartEvent) String() string {
return "StartEvent{}"
}
// StopEvent represents stop event
type StopEvent struct{}
func (e StopEvent) String() string {
return "StopEvent{}"
}
// ReadyEvent is a driver ready event
// Means that all retained messages are received
type ReadyEvent struct{}
func (e ReadyEvent) String() string {
return "ReadyEvent{}"
}
// NewExternalDeviceEvent event of external device is detected
// Fires when driver receives first message with matching topic
// Passes new ExternalDevice object representing this device
type NewExternalDeviceEvent struct {
Device ExternalDevice
}
func (e NewExternalDeviceEvent) String() string {
return fmt.Sprintf("NewExternalDeviceEvent{Device:%s}", e.Device.GetId())
}
// NewExternalDeviceControlEvent a new external device control is detected
// Fires when driver receives first message with matching topic
// Passes new Control object
type NewExternalDeviceControlEvent struct {
Device ExternalDevice
Control Control
}
func (e NewExternalDeviceControlEvent) String() string {
return fmt.Sprintf("NewExternalDeviceControlEvent{Device:%s,Control:%s}", e.Device.GetId(), e.Control.GetId())
}
// NewExternalDeviceMetaEvent a new external device meta received
// Fires when driver receives message with topic matching to some
// external device's meta
type NewExternalDeviceMetaEvent struct {
Device ExternalDevice
Type string
Value string
}
func (e NewExternalDeviceMetaEvent) String() string {
return fmt.Sprintf("NewExternalDeviceMetaEvent{Device:%s,Type:%s,Value:%s}", e.Device.GetId(), e.Type, e.Value)
}
// NewExternalDeviceControlMetaEvent a new external device control metadata received
type NewExternalDeviceControlMetaEvent struct {
Control Control
Type string
Value interface{}
PrevValue interface{}
}
func (e NewExternalDeviceControlMetaEvent) String() string {
return fmt.Sprintf("NewExternalDeviceControlMetaEvent{Device:%s,Control:%s,Type:%s,Value:%s}",
e.Control.GetDevice().GetId(), e.Control.GetId(), e.Type, e.Value)
}
// ControlValueEvent a new device value received
// Device may be either local or external. For local controls
// this event ignored by driver (sent for user handlers only)
type ControlValueEvent struct {
Control Control
RawValue string
PrevRawValue string
}
func (e ControlValueEvent) String() string {
return fmt.Sprintf("ControlValueEvent{Device:%s,Control:%s,Value:%s->%s}", e.Control.GetDevice().GetId(),
e.Control.GetId(), e.PrevRawValue, e.RawValue)
}
// ControlOnValueEvent control received 'on' value
// Valid for local devices only
type ControlOnValueEvent struct {
Control Control
RawValue string
}
func (e ControlOnValueEvent) String() string {
return fmt.Sprintf("ControlOnValueEvent{Device:%s,Control:%s,Value:%s}", e.Control.GetDevice().GetId(),
e.Control.GetId(), e.RawValue)
}