mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
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
This commit is contained in:
parent
a30ca4307b
commit
07f20676cb
@ -25,6 +25,8 @@ ATTR_OVERWRITE = 'overwrite'
|
|||||||
CONF_DOWNLOAD_DIR = 'download_dir'
|
CONF_DOWNLOAD_DIR = 'download_dir'
|
||||||
|
|
||||||
DOMAIN = 'downloader'
|
DOMAIN = 'downloader'
|
||||||
|
DOWNLOAD_FAILED_EVENT = 'download_failed'
|
||||||
|
DOWNLOAD_COMPLETED_EVENT = 'download_completed'
|
||||||
|
|
||||||
SERVICE_DOWNLOAD_FILE = 'download_file'
|
SERVICE_DOWNLOAD_FILE = 'download_file'
|
||||||
|
|
||||||
@ -133,9 +135,19 @@ def setup(hass, config):
|
|||||||
fil.write(chunk)
|
fil.write(chunk)
|
||||||
|
|
||||||
_LOGGER.debug("Downloading of %s done", url)
|
_LOGGER.debug("Downloading of %s done", url)
|
||||||
|
hass.bus.fire(
|
||||||
|
"{}_{}".format(DOMAIN, DOWNLOAD_COMPLETED_EVENT), {
|
||||||
|
'url': url,
|
||||||
|
'filename': filename
|
||||||
|
})
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.exception("ConnectionError occurred for %s", url)
|
_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
|
# Remove file if we started downloading but failed
|
||||||
if final_path and os.path.isfile(final_path):
|
if final_path and os.path.isfile(final_path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user