viri-leds-dmx-sacn/main.py

77 lines
1.8 KiB
Python
Executable file

#!/usr/bin/env python3
import logging
from argparse import ArgumentParser
from queue import Queue
from sys import exit
from time import sleep
from conf import load_and_validate_config
from dmx_queue import DMXQueue
from lights.ignition_wal_l710 import IgnitionWALL710
from lights.varytec_hero_wash_zoom_712 import VarytecHeroWashZoom712
from lights.wled import WLED
from mqtt_queue import MQTTQueue
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(name)20s [%(levelname)-8s] %(message)s',
)
LOG = logging.getLogger('main')
def main():
parser = ArgumentParser()
parser.add_argument(
'--config',
default='config.toml',
)
args = parser.parse_args()
config = load_and_validate_config(args.config)
LOG.info('Welcome to Voc2DMX')
queue = Queue()
lights = []
for addr in config['lights'].get('ignition_wal_l710', []):
lights.append(IgnitionWALL710(addr))
for addr in config['lights'].get('varytec_hero_wash_712_zoom', []):
lights.append(VarytecHeroWashZoom712(addr))
for addr in config['lights'].get('wled_multi_rgb', []):
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(config, queue)
dmxq = DMXQueue(config, 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()