Total Complexity | 5 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import signal |
||
2 | from threading import Thread |
||
3 | |||
4 | from pyhap.accessory import Bridge |
||
5 | from pyhap.accessory_driver import AccessoryDriver |
||
6 | |||
7 | from ._Master import MasterLight |
||
8 | from ._RGB import RGBLight |
||
9 | |||
10 | driver = None |
||
11 | |||
12 | |||
13 | def run(controller): |
||
14 | global driver |
||
15 | if driver is not None: return |
||
16 | |||
17 | driver = AccessoryDriver() |
||
18 | |||
19 | bridge = Bridge(driver, 'PyDMXControl') |
||
20 | bridge.set_info_service(manufacturer="PyDMXControl", |
||
21 | model="Central Controller", |
||
22 | serial_number="Chans: 1->{} (All)".format(controller.next_channel - 1)) |
||
23 | |||
24 | for fixture in controller.get_all_fixtures(): |
||
25 | bridge.add_accessory(RGBLight(fixture, driver)) |
||
26 | |||
27 | bridge.add_accessory(MasterLight(controller, driver)) |
||
28 | |||
29 | signal.signal(signal.SIGTERM, driver.signal_handler) |
||
30 | driver.add_accessory(accessory=bridge) |
||
31 | |||
32 | thread = Thread(target=driver.start) |
||
33 | thread.daemon = True |
||
34 | thread.start() |
||
35 | |||
36 | |||
37 | def stop(): |
||
38 | global driver |
||
39 | if driver is None: return |
||
40 | driver.stop() |
||
41 |