-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
57 lines (46 loc) · 1.22 KB
/
test.py
File metadata and controls
57 lines (46 loc) · 1.22 KB
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
import time
import pg
from rules import *
from device import *
from device_serial_updater import *
aset = ActionSet(1)
aset.actions = []
cset = ConditionSet(1)
cset.conditions = []
devices = []
for i in range(1,6):
name = 'led' + str(i)
port = 8 + i
a = Action(i, name, 0, 1) # id, name, duration, value
aset.actions.append(a)
d = Device(name, port, Device.FLOW_OUT)
devices.append(d)
name = 'light1'
port = 16
c = Condition(1, name, Condition.C_LT, 100)
cset.conditions.append(c)
ls = Device(name, port, Device.FLOW_IN)
devices.append(ls)
con = pg.connect('autohome_development', 'menlohotels.com', 5432, None, None, 'autohome', 'autohome')
try:
dss = DeviceSerialPush(devices);
dsl = DeviceSerialPull(devices);
dss.start()
dsl.start()
except (KeyboardInterrupt, SystemExit):
print '\n! Received keyboard interrupt, quitting threads.\n'
sys.exit()
rs = RuleSet(1)
rs.condition_set = cset
rs.action_set = aset
while 1:
if rs.execute(devices) == True:
pass
else:
for d in devices:
if d.getFlow() == Device.FLOW_OUT:
d.setValue(0)
for d in devices:
if d.getFlow() == Device.FLOW_IN:
print d.toString()
time.sleep(.1)