diff --git a/homeassistant/components/teslemetry/__init__.py b/homeassistant/components/teslemetry/__init__.py index 89bb318c4b7..50767de7e46 100644 --- a/homeassistant/components/teslemetry/__init__.py +++ b/homeassistant/components/teslemetry/__init__.py @@ -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) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 8ab74123d02..71b9b0d0cb0 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -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: diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 7f0ab120a70..51cd11ed5f7 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -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(