Esempio n. 1
0
def write_cpp(config):
    _LOGGER.info("Generating C++ source...")

    CORE.add_job(core_config.to_code, config[CONF_ESPHOME], domain='esphome')
    for domain in PRE_INITIALIZE:
        if domain == CONF_ESPHOME or domain not in config:
            continue
        CORE.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
        CORE.add_job(component.to_code, conf, domain=domain)

    CORE.flush_tasks()
    add(RawStatement(''))
    add(RawStatement(''))
    all_code = []
    for exp in CORE.expressions:
        if not config[CONF_ESPHOME][CONF_USE_CUSTOM_CODE]:
            if isinstance(exp, Expression) and not exp.required:
                continue
        all_code.append(text_type(statement(exp)))

    writer.write_platformio_project()

    code_s = indent('\n'.join(line.rstrip() for line in all_code))
    writer.write_cpp(code_s)
    return 0
Esempio n. 2
0
def load_components():
    import esphome.config_validation as cv
    from esphome.config import get_component

    modules["cv"] = cv
    from esphome import automation

    modules["automation"] = automation

    for domain in get_dirs():
        components[domain] = get_component(domain)
        modules[domain] = components[domain].module
Esempio n. 3
0
parts = [BASE]

# Fake some diretory so that get_component works
CORE.config_path = str(root)

codeowners = defaultdict(list)

for path in components_dir.iterdir():
    if not path.is_dir():
        continue
    if not (path / '__init__.py').is_file():
        continue

    name = path.name
    comp = get_component(name)
    if comp is None:
        print(
            f'Cannot find component {name}. Make sure current path is pip installed ESPHome'
        )
        sys.exit(1)

    codeowners[f'esphome/components/{name}/*'].extend(comp.codeowners)

    for platform_path in path.iterdir():
        platform_name = platform_path.stem
        platform = get_platform(platform_name, name)
        if platform is None:
            continue

        if platform_path.is_dir():
Esempio n. 4
0
def load_components():
    from esphome.config import get_component

    for domain in get_component_names():
        components[domain] = get_component(domain)