Change webdav namespace to absolut URI (#139456)

* Change webdav namespace to absolut URI

* Add const file
pull/139859/head
Jan-Philipp Benecke 2025-02-28 11:18:16 +01:00 committed by Bram Kragten
parent 46ec3987a8
commit 3985f1c6c8
2 changed files with 9 additions and 8 deletions

View File

@ -30,6 +30,7 @@ _LOGGER = logging.getLogger(__name__)
METADATA_VERSION = "1" METADATA_VERSION = "1"
BACKUP_TIMEOUT = ClientTimeout(connect=10, total=43200) BACKUP_TIMEOUT = ClientTimeout(connect=10, total=43200)
NAMESPACE = "https://home-assistant.io"
async def async_get_backup_agents( async def async_get_backup_agents(
@ -100,14 +101,14 @@ def _is_current_metadata_version(properties: list[Property]) -> bool:
return any( return any(
prop.value == METADATA_VERSION prop.value == METADATA_VERSION
for prop in properties for prop in properties
if prop.namespace == "homeassistant" and prop.name == "metadata_version" if prop.namespace == NAMESPACE and prop.name == "metadata_version"
) )
def _backup_id_from_properties(properties: list[Property]) -> str | None: def _backup_id_from_properties(properties: list[Property]) -> str | None:
"""Return the backup ID from properties.""" """Return the backup ID from properties."""
for prop in properties: for prop in properties:
if prop.namespace == "homeassistant" and prop.name == "backup_id": if prop.namespace == NAMESPACE and prop.name == "backup_id":
return prop.value return prop.value
return None return None
@ -186,12 +187,12 @@ class WebDavBackupAgent(BackupAgent):
f"{self._backup_path}/{filename_meta}", f"{self._backup_path}/{filename_meta}",
[ [
Property( Property(
namespace="homeassistant", namespace=NAMESPACE,
name="backup_id", name="backup_id",
value=backup.backup_id, value=backup.backup_id,
), ),
Property( Property(
namespace="homeassistant", namespace=NAMESPACE,
name="metadata_version", name="metadata_version",
value=METADATA_VERSION, value=METADATA_VERSION,
), ),
@ -252,11 +253,11 @@ class WebDavBackupAgent(BackupAgent):
self._backup_path, self._backup_path,
[ [
PropertyRequest( PropertyRequest(
namespace="homeassistant", namespace=NAMESPACE,
name="metadata_version", name="metadata_version",
), ),
PropertyRequest( PropertyRequest(
namespace="homeassistant", namespace=NAMESPACE,
name="backup_id", name="backup_id",
), ),
], ],

View File

@ -20,12 +20,12 @@ MOCK_LIST_WITH_PROPERTIES = {
"/Automatic_backup_2025.2.1_2025-02-10_18.31_30202686.tar": [], "/Automatic_backup_2025.2.1_2025-02-10_18.31_30202686.tar": [],
"/Automatic_backup_2025.2.1_2025-02-10_18.31_30202686.metadata.json": [ "/Automatic_backup_2025.2.1_2025-02-10_18.31_30202686.metadata.json": [
Property( Property(
namespace="homeassistant", namespace="https://home-assistant.io",
name="backup_id", name="backup_id",
value="23e64aec", value="23e64aec",
), ),
Property( Property(
namespace="homeassistant", namespace="https://home-assistant.io",
name="metadata_version", name="metadata_version",
value="1", value="1",
), ),