mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 15:31:52 -05:00
Tolerate unloading a never-loaded config entry in EntityComponent (#176594)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
co-authored by
Claude Fable 5
Erik Montnemery
parent
08c4f686bf
commit
fd8a165c97
@@ -198,7 +198,18 @@ class EntityComponent[_EntityT: entity.Entity = entity.Entity]:
|
||||
key = config_entry.entry_id
|
||||
|
||||
if (platform := self._platforms.pop(key, None)) is None:
|
||||
raise ValueError("Config entry was never loaded!")
|
||||
self.logger.warning(
|
||||
(
|
||||
"Ignored unload request for config entry %s (%s) in %s.%s; "
|
||||
"no platform is loaded, it was never set up "
|
||||
"or has already been unloaded"
|
||||
),
|
||||
config_entry.title,
|
||||
key,
|
||||
config_entry.domain,
|
||||
self.domain,
|
||||
)
|
||||
return True
|
||||
|
||||
await platform.async_reset()
|
||||
return True
|
||||
|
||||
@@ -420,13 +420,19 @@ async def test_unload_entry_resets_platform(hass: HomeAssistant) -> None:
|
||||
assert len(hass.states.async_entity_ids()) == 0
|
||||
|
||||
|
||||
async def test_unload_entry_fails_if_never_loaded(hass: HomeAssistant) -> None:
|
||||
"""."""
|
||||
async def test_unload_entry_tolerates_never_loaded(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test unloading an entry that was never loaded succeeds with a warning."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
entry = MockConfigEntry(domain="entry_domain")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await component.async_unload_entry(entry)
|
||||
assert await component.async_unload_entry(entry)
|
||||
assert (
|
||||
f"Ignored unload request for config entry Mock Title ({entry.entry_id}) "
|
||||
f"in entry_domain.{DOMAIN}; no platform is loaded, it was never set up "
|
||||
"or has already been unloaded"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
async def test_update_entity(hass: HomeAssistant) -> None:
|
||||
|
||||
Reference in New Issue
Block a user