Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,18 @@ def __init__(self, hass: HomeAssistant, hass_config: dict) -> None:
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:
Expand Down
42 changes: 41 additions & 1 deletion tests/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down