mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove ConfigEntry runtime_data on unload (#117312)
This commit is contained in:
parent
a1bc929421
commit
3434fb70fb
@ -127,6 +127,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload Teslemetry Config."""
|
"""Unload Teslemetry Config."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
del entry.runtime_data
|
|
||||||
return unload_ok
|
|
||||||
|
@ -802,6 +802,8 @@ class ConfigEntry(Generic[_DataT]):
|
|||||||
if domain_is_integration:
|
if domain_is_integration:
|
||||||
if result:
|
if result:
|
||||||
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
|
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)
|
await self._async_process_on_unload(hass)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
@ -1581,6 +1581,7 @@ async def test_entry_unload_succeed(
|
|||||||
"""Test that we can unload an entry."""
|
"""Test that we can unload an entry."""
|
||||||
entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED)
|
entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
entry.runtime_data = 2
|
||||||
|
|
||||||
async_unload_entry = AsyncMock(return_value=True)
|
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 await manager.async_unload(entry.entry_id)
|
||||||
assert len(async_unload_entry.mock_calls) == 1
|
assert len(async_unload_entry.mock_calls) == 1
|
||||||
assert entry.state is config_entries.ConfigEntryState.NOT_LOADED
|
assert entry.state is config_entries.ConfigEntryState.NOT_LOADED
|
||||||
|
assert not hasattr(entry, "runtime_data")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user