Source code for duco.command_line

#! /usr/bin/python
"""Command line tool that wraps Python Duco."""
import logging
import argparse
from duco.const import (PROJECT_PACKAGE_NAME)
from duco.enum_types import (ModuleType, ZoneAction)
from duco.duco import (DucoBox)


_LOGGER = logging.getLogger(PROJECT_PACKAGE_NAME)


[docs]def configure_logging(): """Configure logging for command line.""" _LOGGER.setLevel(logging.DEBUG) # create console handler and set level to debug console = logging.StreamHandler() console.setLevel(logging.DEBUG) # create formatter formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') # add formatter to console console.setFormatter(formatter) # add console to logger _LOGGER.addHandler(console)
[docs]def parse_args(): """Parse command line arguments.""" description = 'Command line interface to Duco Ventilation System' parser = argparse.ArgumentParser(description=description) parser.add_argument('--type', dest='modbus_type', default='serial', help='modbus client type; ' 'supported: serial, tcp') parser.add_argument('--port', dest='modbus_port', help='modbus client port ') parser.add_argument('--host', dest='modbus_host', default='localhost', help='optional, modbus tcp host') return parser.parse_args()
[docs]def main(): """Execute main function.""" args = parse_args() configure_logging() with DucoBox(args.modbus_type, args.modbus_port, args.modbus_host) as duco_box: for node in duco_box.node_list: print(node) if node.node_type == ModuleType.USER_CONTROLLER: node.action = ZoneAction.ZONE_TO_AUTO print(node)
if __name__ == '__main__': main()