Example #1
0
def command_hass_config(args, config):
    from esphomeyaml.components import mqtt as mqtt_component

    _LOGGER.info(
        "This is what you should put in your Home Assistant YAML configuration."
    )
    _LOGGER.info(
        "Please note this is only necessary if you're not using MQTT discovery."
    )
    data = mqtt_component.GenerateHassConfigData(config)
    hass_config = OrderedDict()
    for domain, component, conf in iter_components(config):
        if not hasattr(component, 'to_hass_config'):
            continue
        func = getattr(component, 'to_hass_config')
        ret = func(data, conf)
        if not isinstance(ret, (list, tuple)):
            ret = [ret]
        ret = [x for x in ret if x is not None]
        domain_conf = hass_config.setdefault(domain.split('.')[0], [])
        domain_conf += ret

    safe_print(yaml_util.dump(hass_config))
    return 0
Example #2
0
def command_config(args, config):
    print(yaml_util.dump(config))
    return 0
Example #3
0
def command_config(args, config):
    if not args.verbose:
        config = strip_default_ids(config)
    print(yaml_util.dump(config))
    return 0
Example #4
0
def command_config(args, config):
    _LOGGER.info("Configuration is valid!")
    if not args.verbose:
        config = strip_default_ids(config)
    safe_print(yaml_util.dump(config))
    return 0
Example #5
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