Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions homeassistant/components/knx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .const import (
CONF_KNX_EXPOSE,
CONF_KNX_KNXKEY_FILENAME,
CONF_KNX_TELEGRAM_DB_PATH,
DATA_HASS_CONFIG,
DOMAIN,
KNX_MODULE_KEY,
Expand Down Expand Up @@ -51,7 +52,6 @@
)
from .services import async_setup_services
from .storage.config_store import STORAGE_KEY as CONFIG_STORAGE_KEY
from .telegrams import STORAGE_KEY as TELEGRAMS_STORAGE_KEY
from .websocket import register_panel

_KNX_YAML_CONFIG: Final = "knx_yaml_config"
Expand Down Expand Up @@ -142,7 +142,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)

await register_panel(hass)

return True


Expand Down Expand Up @@ -183,7 +182,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Remove a config entry."""

def remove_files(storage_dir: Path, knxkeys_filename: str | None) -> None:
def remove_files(
storage_dir: Path, knxkeys_filename: str | None, db_path: str | None
) -> None:
"""Remove KNX files."""
if knxkeys_filename is not None:
with contextlib.suppress(FileNotFoundError):
Expand All @@ -193,13 +194,21 @@ def remove_files(storage_dir: Path, knxkeys_filename: str | None) -> None:
with contextlib.suppress(FileNotFoundError):
(storage_dir / PROJECT_STORAGE_KEY).unlink()
with contextlib.suppress(FileNotFoundError):
(storage_dir / TELEGRAMS_STORAGE_KEY).unlink()
(storage_dir / "knx/telegrams_history.json").unlink()
with contextlib.suppress(FileNotFoundError):
(storage_dir / "knx/telegrams.db").unlink()
if db_path is not None:
with contextlib.suppress(FileNotFoundError):
(storage_dir / db_path).unlink()
Comment on lines +199 to +202
with contextlib.suppress(FileNotFoundError, OSError):
(storage_dir / DOMAIN).rmdir()

storage_dir = Path(hass.config.path(STORAGE_DIR))
knxkeys_filename = entry.data.get(CONF_KNX_KNXKEY_FILENAME)
await hass.async_add_executor_job(remove_files, storage_dir, knxkeys_filename)
db_path = entry.data.get(CONF_KNX_TELEGRAM_DB_PATH)
await hass.async_add_executor_job(
remove_files, storage_dir, knxkeys_filename, db_path
)


async def async_remove_config_entry_device(
Expand Down
Loading
Loading