mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Simplify custom component loading (#128813)
This commit is contained in:
parent
e8acb48b1e
commit
28ff138370
@ -283,9 +283,7 @@ def manifest_from_legacy_module(domain: str, module: ModuleType) -> Manifest:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def _async_get_custom_components(
|
def _get_custom_components(hass: HomeAssistant) -> dict[str, Integration]:
|
||||||
hass: HomeAssistant,
|
|
||||||
) -> dict[str, Integration]:
|
|
||||||
"""Return list of custom integrations."""
|
"""Return list of custom integrations."""
|
||||||
if hass.config.recovery_mode or hass.config.safe_mode:
|
if hass.config.recovery_mode or hass.config.safe_mode:
|
||||||
return {}
|
return {}
|
||||||
@ -295,21 +293,14 @@ async def _async_get_custom_components(
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_sub_directories(paths: list[str]) -> list[pathlib.Path]:
|
dirs = [
|
||||||
"""Return all sub directories in a set of paths."""
|
entry
|
||||||
return [
|
for path in custom_components.__path__
|
||||||
entry
|
for entry in pathlib.Path(path).iterdir()
|
||||||
for path in paths
|
if entry.is_dir()
|
||||||
for entry in pathlib.Path(path).iterdir()
|
]
|
||||||
if entry.is_dir()
|
|
||||||
]
|
|
||||||
|
|
||||||
dirs = await hass.async_add_executor_job(
|
integrations = _resolve_integrations_from_root(
|
||||||
get_sub_directories, custom_components.__path__
|
|
||||||
)
|
|
||||||
|
|
||||||
integrations = await hass.async_add_executor_job(
|
|
||||||
_resolve_integrations_from_root,
|
|
||||||
hass,
|
hass,
|
||||||
custom_components,
|
custom_components,
|
||||||
[comp.name for comp in dirs],
|
[comp.name for comp in dirs],
|
||||||
@ -330,7 +321,7 @@ async def async_get_custom_components(
|
|||||||
if comps_or_future is None:
|
if comps_or_future is None:
|
||||||
future = hass.data[DATA_CUSTOM_COMPONENTS] = hass.loop.create_future()
|
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
|
hass.data[DATA_CUSTOM_COMPONENTS] = comps
|
||||||
future.set_result(comps)
|
future.set_result(comps)
|
||||||
|
@ -818,7 +818,7 @@ async def test_get_custom_components(hass: HomeAssistant) -> None:
|
|||||||
test_1_integration = _get_test_integration(hass, "test_1", False)
|
test_1_integration = _get_test_integration(hass, "test_1", False)
|
||||||
test_2_integration = _get_test_integration(hass, "test_2", True)
|
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:
|
with patch(name) as mock_get:
|
||||||
mock_get.return_value = {
|
mock_get.return_value = {
|
||||||
"test_1": test_1_integration,
|
"test_1": test_1_integration,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user