diff --git a/script/helpers.py b/script/helpers.py index 447d54fa54..33f95d6f8a 100644 --- a/script/helpers.py +++ b/script/helpers.py @@ -101,7 +101,11 @@ def get_component_from_path(file_path: str) -> str | None: ): parts = file_path.split("/") if len(parts) >= 3 and parts[2]: - return parts[2] + # Verify that parts[2] is actually a component directory, not a file + # like .gitignore or README.md in the components directory itself + component_name = parts[2] + if "." not in component_name: + return component_name return None diff --git a/tests/script/test_helpers.py b/tests/script/test_helpers.py index 1046512a14..5eb55c0722 100644 --- a/tests/script/test_helpers.py +++ b/tests/script/test_helpers.py @@ -1093,6 +1093,11 @@ def test_parse_list_components_output(output: str, expected: list[str]) -> None: ("tests/components/", None), # No component name ("esphome/components", None), # No trailing slash ("tests/components", None), # No trailing slash + # Files in component directories that are not components + ("tests/components/.gitignore", None), # Hidden file + ("tests/components/README.md", None), # Documentation file + ("esphome/components/__init__.py", None), # Python init file + ("tests/components/main.cpp", None), # File with extension ], ) def test_get_component_from_path(