mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Do not load ignored or disabled integrations at startup (#48355)
config_entries.async_setup will skip ignored and disabled integrations but bootstrap would still load them in memory even though they would never be setup.
This commit is contained in:
parent
1fb9008488
commit
6023105c6a
@ -630,17 +630,18 @@ class ConfigEntries:
|
|||||||
EntityRegistryDisabledHandler(hass).async_setup()
|
EntityRegistryDisabledHandler(hass).async_setup()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_domains(self) -> list[str]:
|
def async_domains(
|
||||||
|
self, include_ignore: bool = False, include_disabled: bool = False
|
||||||
|
) -> list[str]:
|
||||||
"""Return domains for which we have entries."""
|
"""Return domains for which we have entries."""
|
||||||
seen: set[str] = set()
|
return list(
|
||||||
result = []
|
{
|
||||||
|
entry.domain: None
|
||||||
for entry in self._entries.values():
|
for entry in self._entries.values()
|
||||||
if entry.domain not in seen:
|
if (include_ignore or entry.source != SOURCE_IGNORE)
|
||||||
seen.add(entry.domain)
|
and (include_disabled or not entry.disabled_by)
|
||||||
result.append(entry.domain)
|
}
|
||||||
|
)
|
||||||
return result
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_get_entry(self, entry_id: str) -> ConfigEntry | None:
|
def async_get_entry(self, entry_id: str) -> ConfigEntry | None:
|
||||||
|
@ -473,7 +473,7 @@ async def test_entries_gets_entries(manager):
|
|||||||
assert manager.async_entries("test2") == [entry1, entry2]
|
assert manager.async_entries("test2") == [entry1, entry2]
|
||||||
|
|
||||||
|
|
||||||
async def test_domains_gets_uniques(manager):
|
async def test_domains_gets_domains_uniques(manager):
|
||||||
"""Test we only return each domain once."""
|
"""Test we only return each domain once."""
|
||||||
MockConfigEntry(domain="test").add_to_manager(manager)
|
MockConfigEntry(domain="test").add_to_manager(manager)
|
||||||
MockConfigEntry(domain="test2").add_to_manager(manager)
|
MockConfigEntry(domain="test2").add_to_manager(manager)
|
||||||
@ -484,6 +484,46 @@ async def test_domains_gets_uniques(manager):
|
|||||||
assert manager.async_domains() == ["test", "test2", "test3"]
|
assert manager.async_domains() == ["test", "test2", "test3"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_domains_gets_domains_excludes_ignore_and_disabled(manager):
|
||||||
|
"""Test we only return each domain once."""
|
||||||
|
MockConfigEntry(domain="test").add_to_manager(manager)
|
||||||
|
MockConfigEntry(domain="test2").add_to_manager(manager)
|
||||||
|
MockConfigEntry(domain="test2").add_to_manager(manager)
|
||||||
|
MockConfigEntry(
|
||||||
|
domain="ignored", source=config_entries.SOURCE_IGNORE
|
||||||
|
).add_to_manager(manager)
|
||||||
|
MockConfigEntry(domain="test3").add_to_manager(manager)
|
||||||
|
MockConfigEntry(domain="disabled", disabled_by="user").add_to_manager(manager)
|
||||||
|
assert manager.async_domains() == ["test", "test2", "test3"]
|
||||||
|
assert manager.async_domains(include_ignore=False) == ["test", "test2", "test3"]
|
||||||
|
assert manager.async_domains(include_disabled=False) == ["test", "test2", "test3"]
|
||||||
|
assert manager.async_domains(include_ignore=False, include_disabled=False) == [
|
||||||
|
"test",
|
||||||
|
"test2",
|
||||||
|
"test3",
|
||||||
|
]
|
||||||
|
|
||||||
|
assert manager.async_domains(include_ignore=True) == [
|
||||||
|
"test",
|
||||||
|
"test2",
|
||||||
|
"ignored",
|
||||||
|
"test3",
|
||||||
|
]
|
||||||
|
assert manager.async_domains(include_disabled=True) == [
|
||||||
|
"test",
|
||||||
|
"test2",
|
||||||
|
"test3",
|
||||||
|
"disabled",
|
||||||
|
]
|
||||||
|
assert manager.async_domains(include_ignore=True, include_disabled=True) == [
|
||||||
|
"test",
|
||||||
|
"test2",
|
||||||
|
"ignored",
|
||||||
|
"test3",
|
||||||
|
"disabled",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_saving_and_loading(hass):
|
async def test_saving_and_loading(hass):
|
||||||
"""Test that we're saving and loading correctly."""
|
"""Test that we're saving and loading correctly."""
|
||||||
mock_integration(
|
mock_integration(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user