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:
Allen Porter 2023-07-02 19:42:39 -07:00 committed by GitHub
parent 792525b7a2
commit 7d6595f755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -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)

View 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()