viri-leds-dmx-sacn/main.py

91 lines
2.2 KiB
Python
Raw Normal View History

2023-08-07 11:39:15 +00:00
#!/usr/bin/env python3
import logging
from argparse import ArgumentParser
from queue import Queue
from sys import exit
from time import sleep
from dmx_queue import DMXQueue
from mqtt_queue import MQTTQueue
from lights.wled import WLED
from lights.ignition_wal_l710 import IgnitionWALL710
from lights.varytec_hero_wash_zoom_712 import VarytecHeroWashZoom712
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(name)20s [%(levelname)-8s] %(message)s',
)
LOG = logging.getLogger('main')
def main():
parser = ArgumentParser()
# MQTT
parser.add_argument('--mqtt-host', required=True)
parser.add_argument('--mqtt-port', type=int, default=1883)
parser.add_argument('--mqtt-user')
parser.add_argument('--mqtt-pass', '--mqtt-password')
parser.add_argument('--mqtt-topic', default='/voc/alert')
# sACN
sacn = parser.add_mutually_exclusive_group(required=True)
sacn.add_argument('--sacn-multicast', action='store_true')
sacn.add_argument('--sacn-target')
# Lights
parser.add_argument('--ignition-wal-l710', nargs='+', type=int)
parser.add_argument('--varytec-wash-zoom-712', nargs='+', type=int)
parser.add_argument('--wled', nargs='+', type=int)
args = parser.parse_args()
LOG.info('Welcome to Voc2DMX')
LOG.debug(args)
queue = Queue()
lights = []
for addr in args.ignition_wal_l710:
lights.append(IgnitionWALL710(addr))
for addr in args.varytec_wash_zoom_712:
lights.append(VarytecHeroWashZoom712(addr))
for addr in args.wled:
lights.append(WLED(addr))
if not lights:
LOG.error('No lights configured, please add atleast one fixture')
exit(1)
LOG.info('')
LOG.info('Configured lights:')
for light in lights:
LOG.info(light)
LOG.info('')
LOG.info('Initializing worker queues ...')
mqttq = MQTTQueue(args, queue)
dmxq = DMXQueue(args, queue, lights)
mqttq.start()
dmxq.start()
LOG.info('initialization done, now running. Press Ctrl-C to stop')
try:
while True:
sleep(1)
except KeyboardInterrupt:
LOG.warning('Got interrupt, stopping queues ...')
mqttq.stop()
dmxq.stop()
LOG.info('Bye!')
if __name__ == '__main__':
main()