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.
pull/48468/head
J. Nick Koston 2021-03-29 01:06:44 -10:00 committed by GitHub
parent 1fb9008488
commit 6023105c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 11 deletions

View File

@ -630,17 +630,18 @@ class ConfigEntries:
EntityRegistryDisabledHandler(hass).async_setup()
@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."""
seen: set[str] = set()
result = []
for entry in self._entries.values():
if entry.domain not in seen:
seen.add(entry.domain)
result.append(entry.domain)
return result
return list(
{
entry.domain: None
for entry in self._entries.values()
if (include_ignore or entry.source != SOURCE_IGNORE)
and (include_disabled or not entry.disabled_by)
}
)
@callback
def async_get_entry(self, entry_id: str) -> ConfigEntry | None:

View File

@ -473,7 +473,7 @@ async def test_entries_gets_entries(manager):
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."""
MockConfigEntry(domain="test").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"]
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):
"""Test that we're saving and loading correctly."""
mock_integration(