mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Add ConfigEntries.async_get_loaded (#124705)
This commit is contained in:
parent
48292beec8
commit
9cae786f40
@ -1742,6 +1742,16 @@ class ConfigEntries:
|
|||||||
and (include_disabled or not entry.disabled_by)
|
and (include_disabled or not entry.disabled_by)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_loaded_entries(self, domain: str) -> list[ConfigEntry]:
|
||||||
|
"""Return loaded entries for a specific domain.
|
||||||
|
|
||||||
|
This will exclude ignored or disabled config entruis.
|
||||||
|
"""
|
||||||
|
entries = self._entries.get_entries_for_domain(domain)
|
||||||
|
|
||||||
|
return [entry for entry in entries if entry.state == ConfigEntryState.LOADED]
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_entry_for_domain_unique_id(
|
def async_entry_for_domain_unique_id(
|
||||||
self, domain: str, unique_id: str
|
self, domain: str, unique_id: str
|
||||||
|
@ -6001,3 +6001,44 @@ async def test_migration_from_1_2(
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_loaded_entries(
|
||||||
|
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
||||||
|
) -> None:
|
||||||
|
"""Test that we can get loaded config entries."""
|
||||||
|
entry1 = MockConfigEntry(domain="comp")
|
||||||
|
entry1.add_to_hass(hass)
|
||||||
|
entry2 = MockConfigEntry(domain="comp", source=config_entries.SOURCE_IGNORE)
|
||||||
|
entry2.add_to_hass(hass)
|
||||||
|
entry3 = MockConfigEntry(
|
||||||
|
domain="comp", disabled_by=config_entries.ConfigEntryDisabler.USER
|
||||||
|
)
|
||||||
|
entry3.add_to_hass(hass)
|
||||||
|
|
||||||
|
mock_setup = AsyncMock(return_value=True)
|
||||||
|
mock_setup_entry = AsyncMock(return_value=True)
|
||||||
|
mock_unload_entry = AsyncMock(return_value=True)
|
||||||
|
|
||||||
|
mock_integration(
|
||||||
|
hass,
|
||||||
|
MockModule(
|
||||||
|
"comp",
|
||||||
|
async_setup=mock_setup,
|
||||||
|
async_setup_entry=mock_setup_entry,
|
||||||
|
async_unload_entry=mock_unload_entry,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
mock_platform(hass, "comp.config_flow", None)
|
||||||
|
|
||||||
|
assert hass.config_entries.async_loaded_entries("comp") == []
|
||||||
|
|
||||||
|
assert await manager.async_setup(entry1.entry_id)
|
||||||
|
assert not await manager.async_setup(entry2.entry_id)
|
||||||
|
assert not await manager.async_setup(entry3.entry_id)
|
||||||
|
|
||||||
|
assert hass.config_entries.async_loaded_entries("comp") == [entry1]
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_unload(entry1.entry_id)
|
||||||
|
|
||||||
|
assert hass.config_entries.async_loaded_entries("comp") == []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user