-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_lutron.py
87 lines (72 loc) · 2.42 KB
/
test_lutron.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
test_lutron.py
Currently we only test the mutation operations: run() etc.
TODO: Test the read operations too.
"""
import asyncio
import lutron, liplib
config = {
'lutron': {
'illumtarget': {
'system': 'Illumination',
'user': 'mine',
'password': 'yes',
'areas': {
'Entry': [[10615, 'Front Door Keypad', [1, 3, 5, 7, 19]], [101000301, 'Pendant'], [101010101, 'Downlights'], [101010102, 'Bridge Downlights']]
}
},
'qstarg': {
'user': 'mine',
'password': 'yes',
'areas': {
'Kitchen': [[166, 'Radiant Heat'], [177, 'Espresso']]
}
}
}
}
class MockReader:
def __init__(self):
pass
def read(self, size):
return b'blah '
class MockWriter:
def __init__(self, match):
self.match = match
self.state = 0
def write(self, b):
if self.state == 0:
assert b == self.match, b
else:
assert False, self.state
self.state += 1
async def drain(self):
assert self.state == 1, self.state
self.state += 1
def lipsetup(config, targ, client, ebus):
params = lutron.ConfigParams(config['lutron'], targ)
lips = lutron.Lipservice(targ, 23, params, ebus)
lips.lipserver._state = liplib.LipServer.State.Opened
client.manager.target_to_cfparams[targ] = params
client.manager.hostport_to_lipservice[(targ, 23)] = lips
lips.lipserver.reader = MockReader()
return lips
class EventbusStub:
def __init__(self):
pass
def propagate(self, *args):
pass
def add_awaitables_to(self, otherset):
pass
eventbus = EventbusStub()
client = lutron.LutronClient(config, eventbus)
illips = lipsetup(config, 'illumtarget', client, eventbus)
illips.lipserver.writer = MockWriter(b'FADEDIM,50,0,0,01:01:00:03:01\r\n')
lips = lipsetup(config, 'qstarg', client, eventbus)
lips.lipserver.writer = MockWriter(b'#OUTPUT,177,1,0\r\n')
asyncio.run(client.run('illumtarget', 'Pendant', 'setlevel', 50))
assert illips.lipserver.writer.state == 2, illips.lipserver.writer.state
assert lips.lipserver.writer.state == 0, lips.lipserver.writer.state
asyncio.run(client.run('qstarg', 177, 'setlevel', 0))
assert lips.lipserver.writer.state == 2, lips.lipserver.writer.state
assert illips.lipserver.writer.state == 2, illips.lipserver.writer.state
print('success')