mirror of
https://github.com/home-assistant/core.git
synced 2026-07-08 23:34:22 +01:00
d766aae436
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
32 lines
1010 B
Python
32 lines
1010 B
Python
"""Support for functionality to download files."""
|
|
|
|
import os
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import _LOGGER, CONF_DOWNLOAD_DIR
|
|
from .services import async_setup_services
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Listen for download events to download files."""
|
|
download_path = entry.data[CONF_DOWNLOAD_DIR]
|
|
|
|
# If path is relative, we assume relative to Home Assistant config dir
|
|
if not os.path.isabs(download_path):
|
|
download_path = hass.config.path(download_path)
|
|
hass.config_entries.async_update_entry(
|
|
entry, data={**entry.data, CONF_DOWNLOAD_DIR: download_path}
|
|
)
|
|
|
|
if not await hass.async_add_executor_job(os.path.isdir, download_path):
|
|
_LOGGER.error(
|
|
"Download path %s does not exist. File Downloader not active", download_path
|
|
)
|
|
return False
|
|
|
|
async_setup_services(hass)
|
|
|
|
return True
|