-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
60 lines (44 loc) · 1.46 KB
/
example.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
import asyncio
import time
from onyx import ObsidianOnyx
HOST = '192.168.50.13'
PORT = 2323
def show_active(client: ObsidianOnyx):
ts('UPDATE RECEIVED')
for item in client.cueLists:
if item.active or item.transitioning:
print(item)
def ts(obj):
print(f'{time.time():.3f}: {obj}')
async def main():
# setup a client... print out all messages, run custom function on
# backend updates
print('CONNECTING')
client = ObsidianOnyx(HOST, PORT, on_update=show_active, on_message=ts)
# When connected, the client will periodically ask Onyx about the
# current active cuelists and call the on_update function whenever
# a cuelist changes status
await client.connect()
print('CONNECTED')
# example of how to select a cuelist by name
selected = None
for cl in client.cueLists:
if cl.name == 'House Half':
selected = cl
break
print(selected)
# cueLists may also be selected directly using the `cueListMap` dict
# NOTE: the key is an integer even though it's a dict, not a list
selected = client.cueListMap[18] or None
print(selected)
await asyncio.sleep(6)
await client.triggerCueList(selected)
await asyncio.sleep(6)
# use the release method on the cuelist itself
await selected.release()
# The client will remain active until the script closes
# but make sure not to block the thread.
# For example, use asyncio.sleep and not time.sleep
while client.connected:
await asyncio.sleep(10)
asyncio.run(main())