This repository has been archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
events.go
157 lines (126 loc) · 4.33 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package gohome
import (
"fmt"
"github.com/markdaws/gohome/pkg/attr"
)
//TODO: SceneSet
// AutomationTriggeredEvt is fired when a piece of automation is triggered
type AutomationTriggeredEvt struct {
Name string
}
// String returns a debug string
func (e *AutomationTriggeredEvt) String() string {
return fmt.Sprintf("AutomationTriggeredEvt[Name: %s]", e.Name)
}
// SunriseEvt is fired when it is sunrise
type SunriseEvt struct{}
// String returns a debug string
func (e *SunriseEvt) String() string {
return "SunriseEvt"
}
// Sunset is fired when it is sunset
type SunsetEvt struct{}
// String returns a debug string
func (e *SunsetEvt) String() string {
return "SunsetEvt"
}
// FeaturesReportEvt is fired when the system wants certain features to
// report their current values
type FeaturesReportEvt struct {
FeatureIDs map[string]bool
}
// Add adds a feature to the request list
func (e *FeaturesReportEvt) Add(featureID string) {
if e.FeatureIDs == nil {
e.FeatureIDs = make(map[string]bool)
}
e.FeatureIDs[featureID] = true
}
// String returns a debug string
func (e *FeaturesReportEvt) String() string {
return fmt.Sprintf("FeaturesReportEvt[#features: %d]", len(e.FeatureIDs))
}
// FeatureReportingEvt is fired when a devices feature(s) responds to a FeaturesReportEvt
// for the current state of the device features
type FeatureReportingEvt struct {
FeatureID string
Attrs map[string]*attr.Attribute
}
// String returns a debug string
func (e *FeatureReportingEvt) String() string {
return fmt.Sprintf("FeatureReportingEvt[ID: %s]", e.FeatureID)
}
// FeatureAttrsChangedEvt is fired when the system determines an attribute of a feature has changed
// value. Note this is not always reflective of the actual hardware in that when the system first
// starts and has no initial value, this will fire even if the value didn't change on the hardware intially
type FeatureAttrsChangedEvt struct {
FeatureID string
Context string
Attrs map[string]*attr.Attribute
}
// String returns a debug string
func (e *FeatureAttrsChangedEvt) String() string {
return fmt.Sprintf("FeatureAttrsChangedEvt[ID:%s, Context:%s, Attrs:%s]", e.FeatureID, e.Context, e.Attrs)
}
// DeviceProducingEvt is raised when a device starts producing events in the system
type DeviceProducingEvt struct {
Device *Device
}
// String returns a debug string
func (dp *DeviceProducingEvt) String() string {
return fmt.Sprintf("DeviceProducingEvt[%s]", dp.Device)
}
// DeviceLostEvt indicates that connection to a device has been lost
type DeviceLostEvt struct {
DeviceName string
DeviceID string
}
// String returns a debug string
func (dl *DeviceLostEvt) String() string {
return fmt.Sprintf("DeviceLostEvt[ID: %s, Name: %s]", dl.DeviceName, dl.DeviceID)
}
// ClientConnectedEvt is raised when a client registers to get updates for zone and sensor values
type ClientConnectedEvt struct {
ConnectionID string `json:"connectionId"`
MonitorID string `json:"-"`
Origin string `json:"origin"`
}
// String returns a debug string
func (cc *ClientConnectedEvt) String() string {
return fmt.Sprintf("ClientConnectedEvt[ConnID: %s, MonitorID: %s, Origin:%s]",
cc.ConnectionID, cc.MonitorID, cc.Origin)
}
// ClientDisconnectedEvt is raised when a client connection is closed
type ClientDisconnectedEvt struct {
ConnectionID string `json:"connectionId"`
}
// String returns a debug string
func (cc *ClientDisconnectedEvt) String() string {
return fmt.Sprintf("ClientDisconnectedEvt[ConnID: %s", cc.ConnectionID)
}
// UserLoginEvt is fired when a user logs in to the system, or there is an unsuccessful
// login attempt
type UserLoginEvt struct {
Login string `json:"login"`
Success bool `json:"success"`
}
// String returns a debug string
func (ul *UserLoginEvt) String() string {
return fmt.Sprintf("UserLoginEvt[Login: %s, Success: %t]", ul.Login, ul.Success)
}
// UserLogoutEvt is fired when a user logs out of the system explicitly
type UserLogoutEvt struct {
Login string `json:"login"`
}
// String returns a debug string
func (ul *UserLogoutEvt) String() string {
return fmt.Sprintf("UserLogoutEvt[Login: %s]", ul.Login)
}
// ServerStartEvt fires when the server is started
type ServerStartedEvt struct{}
// String returns a debug string
func (e *ServerStartedEvt) String() string {
return "ServerStartEvt"
}
//TODO: Finish device lost plumbing
//TODO: DeviceConnectedEvt