Example #1
0
def add_components():
    from esphome.config import get_platform

    for domain, c in components.items():
        if c.is_platform_component:
            # this is a platform_component, e.g. binary_sensor
            platform_schema = [
                {
                    "type": "object",
                    "properties": {"platform": {"type": "string"}},
                }
            ]
            if domain not in ("output", "display"):
                # output bases are either FLOAT or BINARY so don't add common base for this
                # display bases are either simple or FULL so don't add common base for this
                platform_schema = [
                    {"$ref": f"#/definitions/{domain}.{domain.upper()}_SCHEMA"}
                ] + platform_schema

            base_props[domain] = {"type": "array", "items": {"allOf": platform_schema}}

            add_module_registries(domain, c.module)
            add_module_schemas(domain, c.module)

            # need first to iterate all platforms then iteate components
            # a platform component can have other components as properties,
            # e.g. climate components usually have a temperature sensor

    for domain, c in components.items():
        if (c.config_schema is not None) or c.is_platform_component:
            if c.is_platform_component:
                platform_schema = base_props[domain]["items"]["allOf"]
                for platform in get_dirs():
                    p = get_platform(domain, platform)
                    if p is not None:
                        # this is a platform element, e.g.
                        #   - platform: gpio
                        schema = get_jschema(
                            domain + "-" + platform,
                            p.config_schema,
                            create_return_ref=False,
                        )
                        if (
                            schema
                        ):  # for invalid schemas, None is returned thus is deprecated
                            platform_schema.append(
                                {
                                    "if": {
                                        JSC_PROPERTIES: {
                                            "platform": {"const": platform}
                                        }
                                    },
                                    "then": schema,
                                }
                            )

            elif c.config_schema is not None:
                # adds root components which are not platforms, e.g. api: logger:
                if c.multi_conf:
                    schema = get_jschema(domain, c.config_schema)
                    schema = add_definition_array_or_single_object(schema)
                else:
                    schema = get_jschema(domain, c.config_schema, False)
                base_props[domain] = schema
Example #2
0
    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():
            # Sub foldered platforms get their own line
            if not (platform_path / '__init__.py').is_file():
                continue
            codeowners[f'esphome/components/{name}/{platform_name}/*'].extend(
                platform.codeowners)
            continue

        # Non-subfoldered platforms add to codeowners at component level
        if not platform_path.is_file() or platform_path.name == '__init__.py':
            continue
        codeowners[f'esphome/components/{name}/*'].extend(platform.codeowners)