Make backup file names more user friendly (#136928)

* Make backup file names more user friendly

* Strip backup name

* Strip backup name

* Underscores
This commit is contained in:
Erik Montnemery
2025-01-31 17:33:30 +01:00
committed by GitHub
parent b85b834bdc
commit e18dc063ba
7 changed files with 171 additions and 17 deletions

View File

@@ -20,6 +20,7 @@ from securetar import SecureTarError, SecureTarFile, SecureTarReadError
from homeassistant.backup_restore import password_to_key
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import dt as dt_util
from homeassistant.util.json import JsonObjectType, json_loads_object
from homeassistant.util.thread import ThreadWithException
@@ -117,6 +118,14 @@ def read_backup(backup_path: Path) -> AgentBackup:
)
def suggested_filename(backup: AgentBackup) -> str:
"""Suggest a filename for the backup."""
date = dt_util.parse_datetime(backup.date, raise_on_error=True)
return "_".join(
f"{backup.name} - {date.strftime('%Y-%m-%d %H.%M %S%f')}.tar".split()
)
def validate_password(path: Path, password: str | None) -> bool:
"""Validate the password."""
with tarfile.open(path, "r:", bufsize=BUF_SIZE) as backup_file: