Passed
Push — smart_home ( 02db75...d6105e )
by Matt
03:01
created

PyDMXControl.smart.stop()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 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 MasterDimmer,  MasterColor
8
from ._RGB import RGBLight
9
from ._Callback import Callback
10
11
driver = None
12
13
14
def run(controller, callbacks=None):
15
    if callbacks is None:
16
        callbacks = {}
17
18
    global driver
19
    if driver is not None: return
20
21
    driver = AccessoryDriver()
22
23
    bridge = Bridge(driver, 'PyDMXControl')
24
    bridge.set_info_service(manufacturer="PyDMXControl",
25
                            model="Central Controller",
26
                            serial_number="Chans: 1->{} (All)".format(controller.next_channel - 1))
27
28
    for fixture in controller.get_all_fixtures():
29
        bridge.add_accessory(RGBLight(fixture, driver))
30
31
    bridge.add_accessory(MasterDimmer(controller, driver))
32
    bridge.add_accessory(MasterColor(controller, driver))
33
34
    for name, callback in callbacks.items():
35
        bridge.add_accessory(Callback(name, callback, driver))
36
37
    signal.signal(signal.SIGTERM, driver.signal_handler)
38
    driver.add_accessory(bridge)
39
40
    thread = Thread(target=driver.start)
41
    thread.daemon = True
42
    thread.start()
43
44
45
def stop():
46
    global driver
47
    if driver is None: return
48
    driver.stop()
49