1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 09:38:58 +01:00

Improve config entry state transitions when unloading and removing entries (#138522)

* Improve config entry state transitions when unloading and removing entries

* Update integrations which check for a single loaded entry

* Update tests checking state after unload fails

* Update homeassistant/config_entries.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Erik Montnemery
2025-02-17 18:16:57 +01:00
committed by GitHub
parent ff16e587e8
commit e0795e6d07
17 changed files with 46 additions and 98 deletions
+4 -4
View File
@@ -468,8 +468,8 @@ async def test_remove_entry(
hass: HomeAssistant, entry: config_entries.ConfigEntry
) -> None:
"""Mock removing an entry."""
# Check that the entry is not yet removed from config entries
assert hass.config_entries.async_get_entry(entry.entry_id)
# Check that the entry is no longer in the config entries
assert not hass.config_entries.async_get_entry(entry.entry_id)
remove_entry_calls.append(None)
entity = MockEntity(unique_id="1234", name="Test Entity")
@@ -2623,7 +2623,7 @@ async def test_entry_setup_invalid_state(
("unload_result", "expected_result", "expected_state", "has_runtime_data"),
[
(True, True, config_entries.ConfigEntryState.NOT_LOADED, False),
(False, False, config_entries.ConfigEntryState.LOADED, True),
(False, False, config_entries.ConfigEntryState.FAILED_UNLOAD, True),
],
)
async def test_entry_unload(
@@ -2648,7 +2648,7 @@ async def test_entry_unload(
"""Mock unload entry."""
unload_entry_calls.append(None)
verify_runtime_data()
assert entry.state is config_entries.ConfigEntryState.LOADED
assert entry.state is config_entries.ConfigEntryState.UNLOAD_IN_PROGRESS
return unload_result
entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED)