-
Notifications
You must be signed in to change notification settings - Fork 40
/
events.py
66 lines (50 loc) · 1.58 KB
/
events.py
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
instance = None
class Events:
sessionStarted = list()
sessionEnded = list()
onCharger = list()
offCharger = list()
motionOn = list()
motionOff = list()
@staticmethod
def getInstance():
global instance
if instance is None:
instance = Events()
return instance
def fireSessionStarted(self):
for eventFn in self.sessionStarted:
try:
eventFn()
except Exception as e:
print("Exception in sessionStarted: {}".format(e))
def fireSessionEnded(self):
for eventFn in self.sessionEnded:
try:
eventFn()
except Exception as e:
print("Exception in sessionEnded: {}".format(e))
def fireOnCharger(self):
for eventFn in self.onCharger:
try:
eventFn()
except Exception as e:
print("Exception in onCharger: {}".format(e))
def fireOffCharger(self):
for eventFn in self.offCharger:
try:
eventFn()
except Exception as e:
print("Exception in offCharger: {}".format(e))
def fireMotionOn(self):
for eventFn in self.motionOn:
try:
eventFn()
except Exception as e:
print("Exception in motionOn: {}".format(e))
def fireMotionOff(self):
for eventFn in self.motionOff:
try:
eventFn()
except Exception as e:
print("Exception in motionOff: {}".format(e))