Passed
Pull Request — master (#25)
by Matt
09:18 queued 07:55
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 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