Exemplo n.º 1
0
def run_esphomeyaml(argv):
    args = parse_args(argv)
    CORE.dashboard = args.dashboard

    setup_log(args.verbose)
    if args.command in PRE_CONFIG_ACTIONS:
        try:
            return PRE_CONFIG_ACTIONS[args.command](args)
        except EsphomeyamlError as e:
            _LOGGER.error(e)
            return 1

    CORE.config_path = args.configuration

    config = read_config(args.verbose)
    if config is None:
        return 1
    CORE.config = config

    if args.command in POST_CONFIG_ACTIONS:
        try:
            return POST_CONFIG_ACTIONS[args.command](args, config)
        except EsphomeyamlError as e:
            _LOGGER.error(e)
            return 1
    safe_print(u"Unknown command {}".format(args.command))
    return 1
Exemplo n.º 2
0
def run_esphomeyaml(argv):
    setup_log()
    args = parse_args(argv)
    if args.command in PRE_CONFIG_ACTIONS:
        try:
            return PRE_CONFIG_ACTIONS[args.command](args)
        except ESPHomeYAMLError as e:
            _LOGGER.error(e)
            return 1

    core.CONFIG_PATH = args.configuration

    config = read_config(core.CONFIG_PATH)
    if config is None:
        return 1

    if args.command in POST_CONFIG_ACTIONS:
        try:
            return POST_CONFIG_ACTIONS[args.command](args, config)
        except ESPHomeYAMLError as e:
            _LOGGER.error(e)
            return 1
    print(u"Unknown command {}".format(args.command))
    return 1
Exemplo n.º 3
0
def main():
    setup_log()

    parser = argparse.ArgumentParser(prog='esphomeyaml')
    parser.add_argument('configuration', help='Your YAML configuration file.')
    subparsers = parser.add_subparsers(help='Commands', dest='command')
    subparsers.required = True
    subparsers.add_parser('config',
                          help='Validate the configuration and spit it out.')

    subparsers.add_parser('compile',
                          help='Read the configuration and compile a program.')

    parser_upload = subparsers.add_parser('upload',
                                          help='Validate the configuration '
                                          'and upload the latest binary.')
    parser_upload.add_argument('--upload-port',
                               help="Manually specify the upload port to use. "
                               "For example /dev/cu.SLAB_USBtoUART.")
    parser_upload.add_argument('--host-port',
                               help="Specify the host port.",
                               type=int)

    parser_logs = subparsers.add_parser('logs',
                                        help='Validate the configuration '
                                        'and show all MQTT logs.')
    parser_logs.add_argument('--topic',
                             help='Manually set the topic to subscribe to.')
    parser_logs.add_argument('--username', help='Manually set the username.')
    parser_logs.add_argument('--password', help='Manually set the password.')
    parser_logs.add_argument('--client-id', help='Manually set the client id.')
    parser_logs.add_argument('--serial-port',
                             help="Manually specify a serial port to use"
                             "For example /dev/cu.SLAB_USBtoUART.")

    parser_run = subparsers.add_parser(
        'run',
        help='Validate the configuration, create a binary, '
        'upload it, and start MQTT logs.')
    parser_run.add_argument('--upload-port',
                            help="Manually specify the upload port to use. "
                            "For example /dev/cu.SLAB_USBtoUART.")
    parser_run.add_argument('--host-port',
                            help="Specify the host port to use for OTA",
                            type=int)
    parser_run.add_argument('--no-logs',
                            help='Disable starting MQTT logs.',
                            action='store_true')
    parser_run.add_argument(
        '--topic', help='Manually set the topic to subscribe to for logs.')
    parser_run.add_argument('--username',
                            help='Manually set the MQTT username for logs.')
    parser_run.add_argument('--password',
                            help='Manually set the MQTT password for logs.')
    parser_run.add_argument('--client-id',
                            help='Manually set the client id for logs.')

    parser_clean = subparsers.add_parser(
        'clean-mqtt',
        help="Helper to clear an MQTT topic from "
        "retain messages.")
    parser_clean.add_argument('--topic',
                              help='Manually set the topic to subscribe to.')
    parser_clean.add_argument('--username', help='Manually set the username.')
    parser_clean.add_argument('--password', help='Manually set the password.')
    parser_clean.add_argument('--client-id',
                              help='Manually set the client id.')

    subparsers.add_parser('wizard',
                          help="A helpful setup wizard that will guide "
                          "you through setting up esphomeyaml.")

    subparsers.add_parser('mqtt-fingerprint',
                          help="Get the SSL fingerprint from a MQTT broker.")
    subparsers.add_parser('version',
                          help="Print the esphomeyaml version and exit.")

    args = parser.parse_args()

    if args.command == 'wizard':
        return wizard.wizard(args.configuration)

    core.CONFIG_PATH = args.configuration

    config = read_config(core.CONFIG_PATH)
    if config is None:
        return 1

    if args.command == 'config':
        print(yaml_util.dump(config))
        return 0
    elif args.command == 'compile':
        exit_code = write_cpp(config)
        if exit_code != 0:
            return exit_code
        exit_code = compile_program(config)
        if exit_code != 0:
            return exit_code
        _LOGGER.info(u"Successfully compiled program.")
        return 0
    elif args.command == 'upload':
        port = args.upload_port or discover_serial_ports()
        exit_code = upload_program(config, args, port)
        if exit_code != 0:
            return exit_code
        _LOGGER.info(u"Successfully uploaded program.")
        return 0
    elif args.command == 'logs':
        port = args.serial_port or discover_serial_ports()
        return show_logs(config, args, port)
    elif args.command == 'clean-mqtt':
        return clean_mqtt(config, args)
    elif args.command == 'mqtt-fingerprint':
        return mqtt.get_fingerprint(config)
    elif args.command == 'run':
        exit_code = write_cpp(config)
        if exit_code != 0:
            return exit_code
        exit_code = compile_program(config)
        if exit_code != 0:
            return exit_code
        _LOGGER.info(u"Successfully compiled program.")
        port = args.upload_port or discover_serial_ports()
        exit_code = upload_program(config, args, port)
        if exit_code != 0:
            return exit_code
        _LOGGER.info(u"Successfully uploaded program.")
        if args.no_logs:
            return 0
        return show_logs(config, args, port)
    elif args.command == 'version':
        print(u"Version: {}".format(const.__version__))
        return 0
    print(u"Unknown command {}".format(args.command))
    return 1