def main(): logger.info("Starting Paradox Alarm Interface") logger.info("Console Log level set to {}".format(cfg.LOGGING_LEVEL_CONSOLE)) interface_manager = InterfaceManager(config=cfg) interface_manager.start() time.sleep(1) # Load a connection to the alarm if cfg.CONNECTION_TYPE == "Serial": logger.info("Using Serial Connection") from paradox.connections.serial_connection import SerialCommunication connection = SerialCommunication(port=cfg.SERIAL_PORT) elif cfg.CONNECTION_TYPE == 'IP': logger.info("Using IP Connection") from paradox.connections.ip_connection import IPConnection connection = IPConnection(host=cfg.IP_CONNECTION_HOST, port=cfg.IP_CONNECTION_PORT, password=cfg.IP_CONNECTION_PASSWORD) else: logger.error("Invalid connection type: {}".format(cfg.CONNECTION_TYPE)) sys.exit(-1) # Start interacting with the alarm alarm = Paradox(connection=connection, interface=interface_manager) retry = 1 while True: logger.info("Starting...") retry_time_wait = 2 ^ retry retry_time_wait = 30 if retry_time_wait > 30 else retry_time_wait try: alarm.disconnect() if alarm.connect(): retry = 1 interface_manager.set_alarm(alarm) alarm.loop() else: logger.error("Unable to connect to alarm") time.sleep(retry_time_wait) except (ConnectionError, OSError): # Connection to IP Module or MQTT lost logger.exception("Restarting") time.sleep(retry_time_wait) except (KeyboardInterrupt, SystemExit): logger.info("Exit start") if alarm: alarm.disconnect() break # break exits the retry loop except Exception: logger.exception("Restarting") time.sleep(retry_time_wait) retry += 1 interface_manager.stop() logger.info("Good bye!")
def main(args): global alarm, interface_manager if 'config' in args and args.config is not None: import os config_file = os.path.abspath(args.config) cfg.load(config_file) else: cfg.load() config_logger(logger) logger.info("Starting Paradox Alarm Interface") logger.info("Console Log level set to {}".format( cfg.LOGGING_LEVEL_CONSOLE)) interface_manager = InterfaceManager(config=cfg) interface_manager.start() time.sleep(1) signal.signal(signal.SIGINT, exit_handler) # Start interacting with the alarm alarm = Paradox() interface_manager.set_alarm(alarm) retry = 1 while alarm is not None: logger.info("Starting...") retry_time_wait = 2 ^ retry retry_time_wait = 30 if retry_time_wait > 30 else retry_time_wait try: if alarm.connect(): retry = 1 alarm.loop() else: logger.error("Unable to connect to alarm") time.sleep(retry_time_wait) except ConnectionError as e: # Connection to IP Module or MQTT lost logger.error("Connection to panel lost: %s. Restarting" % str(e)) time.sleep(retry_time_wait) except OSError: # Connection to IP Module or MQTT lost logger.exception("Restarting") time.sleep(retry_time_wait) except (KeyboardInterrupt, SystemExit): break # break exits the retry loop except Exception: logger.exception("Restarting") time.sleep(retry_time_wait) retry += 1 exit_handler()
def main(args): global alarm, interface_manager if 'config' in args and args.config is not None: import os config_file = os.path.abspath(args.config) cfg.load(config_file) else: cfg.load() config_logger(logger) logger.info("Starting Paradox Alarm Interface") logger.info("Console Log level set to {}".format( cfg.LOGGING_LEVEL_CONSOLE)) interface_manager = InterfaceManager(config=cfg) interface_manager.start() time.sleep(1) # Load a connection to the alarm if cfg.CONNECTION_TYPE == "Serial": logger.info("Using Serial Connection") from paradox.connections.serial_connection import SerialCommunication connection = SerialCommunication(port=cfg.SERIAL_PORT, baud=cfg.SERIAL_BAUD) elif cfg.CONNECTION_TYPE == 'IP': logger.info("Using IP Connection") from paradox.connections.ip_connection import IPConnection connection = IPConnection(host=cfg.IP_CONNECTION_HOST, port=cfg.IP_CONNECTION_PORT, password=cfg.IP_CONNECTION_PASSWORD) else: logger.error("Invalid connection type: {}".format(cfg.CONNECTION_TYPE)) sys.exit(-1) signal.signal(signal.SIGINT, exit_handler) # Start interacting with the alarm alarm = Paradox(connection=connection, interface=interface_manager) retry = 1 while True: logger.info("Starting...") retry_time_wait = 2 ^ retry retry_time_wait = 30 if retry_time_wait > 30 else retry_time_wait try: if alarm.connect(): retry = 1 interface_manager.set_alarm(alarm) alarm.loop() else: logger.error("Unable to connect to alarm") time.sleep(retry_time_wait) except ConnectionError as e: # Connection to IP Module or MQTT lost logger.error("Connection to panel lost: %s. Restarting" % str(e)) time.sleep(retry_time_wait) except OSError: # Connection to IP Module or MQTT lost logger.exception("Restarting") time.sleep(retry_time_wait) except (KeyboardInterrupt, SystemExit): break # break exits the retry loop except Exception: logger.exception("Restarting") time.sleep(retry_time_wait) retry += 1 exit_handler()