Skip to content

Commit 28ff138

Browse files
authored
Simplify custom component loading (#128813)
1 parent e8acb48 commit 28ff138

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

homeassistant/loader.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ def manifest_from_legacy_module(domain: str, module: ModuleType) -> Manifest:
283283
}
284284

285285

286-
async def _async_get_custom_components(
287-
hass: HomeAssistant,
288-
) -> dict[str, Integration]:
286+
def _get_custom_components(hass: HomeAssistant) -> dict[str, Integration]:
289287
"""Return list of custom integrations."""
290288
if hass.config.recovery_mode or hass.config.safe_mode:
291289
return {}
@@ -295,21 +293,14 @@ async def _async_get_custom_components(
295293
except ImportError:
296294
return {}
297295

298-
def get_sub_directories(paths: list[str]) -> list[pathlib.Path]:
299-
"""Return all sub directories in a set of paths."""
300-
return [
301-
entry
302-
for path in paths
303-
for entry in pathlib.Path(path).iterdir()
304-
if entry.is_dir()
305-
]
306-
307-
dirs = await hass.async_add_executor_job(
308-
get_sub_directories, custom_components.__path__
309-
)
296+
dirs = [
297+
entry
298+
for path in custom_components.__path__
299+
for entry in pathlib.Path(path).iterdir()
300+
if entry.is_dir()
301+
]
310302

311-
integrations = await hass.async_add_executor_job(
312-
_resolve_integrations_from_root,
303+
integrations = _resolve_integrations_from_root(
313304
hass,
314305
custom_components,
315306
[comp.name for comp in dirs],
@@ -330,7 +321,7 @@ async def async_get_custom_components(
330321
if comps_or_future is None:
331322
future = hass.data[DATA_CUSTOM_COMPONENTS] = hass.loop.create_future()
332323

333-
comps = await _async_get_custom_components(hass)
324+
comps = await hass.async_add_executor_job(_get_custom_components, hass)
334325

335326
hass.data[DATA_CUSTOM_COMPONENTS] = comps
336327
future.set_result(comps)

tests/test_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ async def test_get_custom_components(hass: HomeAssistant) -> None:
818818
test_1_integration = _get_test_integration(hass, "test_1", False)
819819
test_2_integration = _get_test_integration(hass, "test_2", True)
820820

821-
name = "homeassistant.loader._async_get_custom_components"
821+
name = "homeassistant.loader._get_custom_components"
822822
with patch(name) as mock_get:
823823
mock_get.return_value = {
824824
"test_1": test_1_integration,

0 commit comments

Comments
 (0)