diff --git a/homeassistant/components/downloader.py b/homeassistant/components/downloader.py index 07f432a5218..5c9ced1fd89 100644 --- a/homeassistant/components/downloader.py +++ b/homeassistant/components/downloader.py @@ -20,6 +20,7 @@ _LOGGER = logging.getLogger(__name__) ATTR_FILENAME = 'filename' ATTR_SUBDIR = 'subdir' ATTR_URL = 'url' +ATTR_OVERWRITE = 'overwrite' CONF_DOWNLOAD_DIR = 'download_dir' @@ -31,6 +32,7 @@ SERVICE_DOWNLOAD_FILE_SCHEMA = vol.Schema({ vol.Required(ATTR_URL): cv.url, vol.Optional(ATTR_SUBDIR): cv.string, vol.Optional(ATTR_FILENAME): cv.string, + vol.Optional(ATTR_OVERWRITE, default=False): cv.boolean, }) CONFIG_SCHEMA = vol.Schema({ @@ -66,6 +68,8 @@ def setup(hass, config): filename = service.data.get(ATTR_FILENAME) + overwrite = service.data.get(ATTR_OVERWRITE) + if subdir: subdir = sanitize_filename(subdir) @@ -109,12 +113,13 @@ def setup(hass, config): # If file exist append a number. # We test filename, filename_2.. - tries = 1 - final_path = path + ext - while os.path.isfile(final_path): - tries += 1 + if not overwrite: + tries = 1 + final_path = path + ext + while os.path.isfile(final_path): + tries += 1 - final_path = "{}_{}.{}".format(path, tries, ext) + final_path = "{}_{}.{}".format(path, tries, ext) _LOGGER.info("%s -> %s", url, final_path)