* Add WebDAV backup agent * Process code review * Increase timeout for large uploads * Make metadata file based * Update IQS * Grammar * Move to aiowebdav2 * Update helper text * Add decorator to handle backup errors * Bump version * Missed one * Add unauth handling * Apply suggestions from code review Co-authored-by: Josef Zweck <josef@zweck.dev> * Update homeassistant/components/webdav/__init__.py * Update homeassistant/components/webdav/config_flow.py * Remove timeout Co-authored-by: Josef Zweck <josef@zweck.dev> * remove unique_id * Add tests * Add missing tests * Bump version * Remove dropbox * Process code review * Bump version to relax pinned dependencies * Process code review * Add translatable exceptions * Process code review * Process code review --------- Co-authored-by: Josef Zweck <josef@zweck.dev>
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""Helper functions for the WebDAV component."""
|
|
|
|
from aiowebdav2.client import Client, ClientOptions
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
|
|
@callback
|
|
def async_create_client(
|
|
*,
|
|
hass: HomeAssistant,
|
|
url: str,
|
|
username: str,
|
|
password: str,
|
|
verify_ssl: bool = False,
|
|
) -> Client:
|
|
"""Create a WebDAV client."""
|
|
return Client(
|
|
url=url,
|
|
username=username,
|
|
password=password,
|
|
options=ClientOptions(
|
|
verify_ssl=verify_ssl,
|
|
session=async_get_clientsession(hass),
|
|
),
|
|
)
|
|
|
|
|
|
async def async_ensure_path_exists(client: Client, path: str) -> bool:
|
|
"""Ensure that a path exists recursively on the WebDAV server."""
|
|
parts = path.strip("/").split("/")
|
|
for i in range(1, len(parts) + 1):
|
|
sub_path = "/".join(parts[:i])
|
|
if not await client.check(sub_path) and not await client.mkdir(sub_path):
|
|
return False
|
|
|
|
return True
|