Skip to content
Snippets Groups Projects
Commit 07f20676 authored by engrbm87's avatar engrbm87 Committed by Paulus Schoutsen
Browse files

Add notifications to downloader.py (#12961)

* Update downloader.py

Add persistent notification to alert when download is finished or in case of download failure.

* Update downloader.py

* Update downloader.py

* Update downloader.py

* Fire and event when download is requested

Added 2 events to represent download completed and download failed. This will allow the user to trigger an automation based on the status of the download.

* Update downloader.py

* Update downloader.py

replaced . with _

* Update downloader.py

fixed linting errors
parent a30ca430
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,8 @@ ATTR_OVERWRITE = 'overwrite'
CONF_DOWNLOAD_DIR = 'download_dir'
DOMAIN = 'downloader'
DOWNLOAD_FAILED_EVENT = 'download_failed'
DOWNLOAD_COMPLETED_EVENT = 'download_completed'
SERVICE_DOWNLOAD_FILE = 'download_file'
......@@ -133,9 +135,19 @@ def setup(hass, config):
fil.write(chunk)
_LOGGER.debug("Downloading of %s done", url)
hass.bus.fire(
"{}_{}".format(DOMAIN, DOWNLOAD_COMPLETED_EVENT), {
'url': url,
'filename': filename
})
except requests.exceptions.ConnectionError:
_LOGGER.exception("ConnectionError occurred for %s", url)
hass.bus.fire(
"{}_{}".format(DOMAIN, DOWNLOAD_FAILED_EVENT), {
'url': url,
'filename': filename
})
# Remove file if we started downloading but failed
if final_path and os.path.isfile(final_path):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment