mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Delete the local calendar store when removing the config entry (#95599)
* Delete calendar store when removing the config entry * Unlink file on remove with tests
This commit is contained in:
parent
792525b7a2
commit
7d6595f755
@ -39,3 +39,14 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Handle removal of an entry."""
|
||||
key = slugify(entry.data[CONF_CALENDAR_NAME])
|
||||
path = Path(hass.config.path(STORAGE_PATH.format(key=key)))
|
||||
|
||||
def unlink(path: Path) -> None:
|
||||
path.unlink(missing_ok=True)
|
||||
|
||||
await hass.async_add_executor_job(unlink, path)
|
||||
|
18
tests/components/local_calendar/test_init.py
Normal file
18
tests/components/local_calendar/test_init.py
Normal file
@ -0,0 +1,18 @@
|
||||
"""Tests for init platform of local calendar."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_remove_config_entry(
|
||||
hass: HomeAssistant, setup_integration: None, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test removing a config entry."""
|
||||
|
||||
with patch("homeassistant.components.local_calendar.Path.unlink") as unlink_mock:
|
||||
assert await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
unlink_mock.assert_called_once()
|
Loading…
x
Reference in New Issue
Block a user