Skip to content
Closed
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
19 changes: 16 additions & 3 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,24 @@ def async_get_entry(self, entry_id: str) -> Optional[ConfigEntry]:
return None

@callback
def async_entries(self, domain: Optional[str] = None) -> List[ConfigEntry]:
def async_entries(
self, domain: Optional[str] = None, include_ignored: bool = True
) -> List[ConfigEntry]:
"""Return all entries or entries for a specific domain."""
if domain is None:
return list(self._entries)
return [entry for entry in self._entries if entry.domain == domain]
if include_ignored:
return list(self._entries)

return [entry for entry in self._entries if entry.source != SOURCE_IGNORE]

if include_ignored:
return [entry for entry in self._entries if entry.domain == domain]

return [
entry
for entry in self._entries
if entry.domain == domain and entry.source != SOURCE_IGNORE
]

async def async_add(self, entry: ConfigEntry) -> None:
"""Add and setup an entry."""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.config_entries import SOURCE_IGNORE
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -1558,3 +1559,15 @@ async def async_step_import(self, user_input):
assert len(entries) == 1
assert entries[0].state == config_entries.ENTRY_STATE_LOADED
assert entries[0].data == {"value": "updated"}

async def test_async_entries_ignore_parameter(hass):
"""Test `include_ignored` parameter in ConfigEntries.async_entries."""
MockConfigEntry(domain="test", entry_id="test1").add_to_hass(hass)
MockConfigEntry(
domain="test", entry_id="test2", source=SOURCE_IGNORE
).add_to_hass(hass)

assert len(hass.config_entries.async_entries("test")) == 2
assert len(hass.config_entries.async_entries("test", False)) == 1
assert len(hass.config_entries.async_entries()) == 2
assert len(hass.config_entries.async_entries(include_ignored=False)) == 1