예제 #1
0
def write_cpp(config):
    _LOGGER.info("Generating C++ source...")

    add_job(core_to_code, config[CONF_ESPHOMEYAML], domain='esphomeyaml')
    for domain in PRE_INITIALIZE:
        if domain == CONF_ESPHOMEYAML or domain not in config:
            continue
        add_job(get_component(domain).to_code, config[domain], domain=domain)

    for domain, component, conf in iter_components(config):
        if domain in PRE_INITIALIZE or not hasattr(component, 'to_code'):
            continue
        add_job(component.to_code, conf, domain=domain)

    flush_tasks()
    add(RawStatement(''))
    add(RawStatement(''))
    all_code = []
    for exp in _EXPRESSIONS:
        if core.SIMPLIFY:
            if isinstance(exp, Expression) and not exp.required:
                continue
            if isinstance(exp, AssignmentExpression) and not exp.obj.required:
                if not exp.has_side_effects():
                    continue
                exp = exp.rhs
        all_code.append(unicode(statement(exp)))

    writer.write_platformio_project(config, get_base_path(config))

    code_s = indent('\n'.join(line.rstrip() for line in all_code))
    cpp_path = os.path.join(get_base_path(config), 'src', 'main.cpp')
    writer.write_cpp(code_s, cpp_path)
    return 0
예제 #2
0
def logger_log_action_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    esp_log = LOG_LEVEL_TO_ESP_LOG[config[CONF_LEVEL]]
    args = [RawExpression(unicode(x)) for x in config[CONF_ARGS]]

    text = unicode(
        statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args)))

    for lambda_ in process_lambda(Lambda(text), [(arg_type, 'x')]):
        yield None
    rhs = LambdaAction.new(template_arg, lambda_)
    type = LambdaAction.template(template_arg)
    yield Pvariable(action_id, rhs, type=type)
예제 #3
0
def write_cpp(config):
    _LOGGER.info("Generating C++ source...")

    add_task(core_to_code, config[CONF_ESPHOMEYAML])
    for domain in PRE_INITIALIZE:
        if domain == CONF_ESPHOMEYAML:
            continue
        if domain in config:
            add_task(get_component(domain).to_code, config[domain])

    # Clear queue
    get_variable(None)
    add(RawStatement(''))

    for domain, component, conf in iter_components(config):
        if domain in PRE_INITIALIZE:
            continue
        if not hasattr(component, 'to_code'):
            continue
        add_task(component.to_code, conf)

    # Clear queue
    get_variable(None)
    add(RawStatement(''))
    add(RawStatement(''))

    all_code = []
    for exp in _EXPRESSIONS:
        if core.SIMPLIFY:
            if isinstance(exp, Expression) and not exp.required:
                continue
            if isinstance(exp, AssignmentExpression) and not exp.obj.required:
                if not exp.has_side_effects():
                    continue
                exp = exp.rhs
        all_code.append(unicode(statement(exp)))

    platformio_ini_s = writer.get_ini_content(config)
    ini_path = os.path.join(get_base_path(config), 'platformio.ini')
    writer.write_platformio_ini(platformio_ini_s, ini_path)

    code_s = indent('\n'.join(line.rstrip() for line in all_code))
    cpp_path = os.path.join(get_base_path(config), 'src', 'main.cpp')
    writer.write_cpp(code_s, cpp_path)
    return 0