diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 68e2a2f2d95..221a2c7ce19 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -283,9 +283,7 @@ def manifest_from_legacy_module(domain: str, module: ModuleType) -> Manifest: } -async def _async_get_custom_components( - hass: HomeAssistant, -) -> dict[str, Integration]: +def _get_custom_components(hass: HomeAssistant) -> dict[str, Integration]: """Return list of custom integrations.""" if hass.config.recovery_mode or hass.config.safe_mode: return {} @@ -295,21 +293,14 @@ async def _async_get_custom_components( except ImportError: return {} - def get_sub_directories(paths: list[str]) -> list[pathlib.Path]: - """Return all sub directories in a set of paths.""" - return [ - entry - for path in paths - for entry in pathlib.Path(path).iterdir() - if entry.is_dir() - ] + dirs = [ + entry + for path in custom_components.__path__ + for entry in pathlib.Path(path).iterdir() + if entry.is_dir() + ] - dirs = await hass.async_add_executor_job( - get_sub_directories, custom_components.__path__ - ) - - integrations = await hass.async_add_executor_job( - _resolve_integrations_from_root, + integrations = _resolve_integrations_from_root( hass, custom_components, [comp.name for comp in dirs], @@ -330,7 +321,7 @@ async def async_get_custom_components( if comps_or_future is None: future = hass.data[DATA_CUSTOM_COMPONENTS] = hass.loop.create_future() - comps = await _async_get_custom_components(hass) + comps = await hass.async_add_executor_job(_get_custom_components, hass) hass.data[DATA_CUSTOM_COMPONENTS] = comps future.set_result(comps) diff --git a/tests/test_loader.py b/tests/test_loader.py index b6889a06666..c4bcbed0107 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -818,7 +818,7 @@ async def test_get_custom_components(hass: HomeAssistant) -> None: test_1_integration = _get_test_integration(hass, "test_1", False) test_2_integration = _get_test_integration(hass, "test_2", True) - name = "homeassistant.loader._async_get_custom_components" + name = "homeassistant.loader._get_custom_components" with patch(name) as mock_get: mock_get.return_value = { "test_1": test_1_integration,