Remove ConfigEntry runtime_data on unload (#117312)

This commit is contained in:
Marc Mueller 2024-05-12 19:53:22 +02:00 committed by GitHub
parent a1bc929421
commit 3434fb70fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View File

@ -127,6 +127,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload Teslemetry Config."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
del entry.runtime_data
return unload_ok
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

View File

@ -802,6 +802,8 @@ class ConfigEntry(Generic[_DataT]):
if domain_is_integration:
if result:
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
if hasattr(self, "runtime_data"):
object.__delattr__(self, "runtime_data")
await self._async_process_on_unload(hass)
except Exception as exc:

View File

@ -1581,6 +1581,7 @@ async def test_entry_unload_succeed(
"""Test that we can unload an entry."""
entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED)
entry.add_to_hass(hass)
entry.runtime_data = 2
async_unload_entry = AsyncMock(return_value=True)
@ -1589,6 +1590,7 @@ async def test_entry_unload_succeed(
assert await manager.async_unload(entry.entry_id)
assert len(async_unload_entry.mock_calls) == 1
assert entry.state is config_entries.ConfigEntryState.NOT_LOADED
assert not hasattr(entry, "runtime_data")
@pytest.mark.parametrize(