diff --git a/custom_components/mail_and_packages/__init__.py b/custom_components/mail_and_packages/__init__.py index 42aad2ee..02308510 100644 --- a/custom_components/mail_and_packages/__init__.py +++ b/custom_components/mail_and_packages/__init__.py @@ -20,6 +20,7 @@ CONF_PATH, CONF_SCAN_INTERVAL, CONF_VERIFY_SSL, + CONFIG_VERSION, COORDINATOR, DEFAULT_AMAZON_DAYS, DOMAIN, @@ -100,7 +101,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> async def async_migrate_entry(hass, config_entry): """Migrate an old config entry.""" version = config_entry.version - new_version = 8 + new_version = CONFIG_VERSION _LOGGER.debug("Migrating from version %s", version) updated_config = {**config_entry.data} @@ -161,6 +162,9 @@ async def async_migrate_entry(hass, config_entry): if CONF_AMAZON_DOMAIN not in updated_config: updated_config[CONF_AMAZON_DOMAIN] = "amazon.com" + if CONF_PATH not in updated_config: + updated_config[CONF_PATH] = "custom_components/mail_and_packages/images/" + if updated_config != config_entry.data: hass.config_entries.async_update_entry( config_entry, data=updated_config, version=new_version diff --git a/custom_components/mail_and_packages/config_flow.py b/custom_components/mail_and_packages/config_flow.py index fdde6cfc..cc2a1468 100644 --- a/custom_components/mail_and_packages/config_flow.py +++ b/custom_components/mail_and_packages/config_flow.py @@ -31,6 +31,7 @@ CONF_PATH, CONF_SCAN_INTERVAL, CONF_VERIFY_SSL, + CONFIG_VERSION, DEFAULT_ALLOW_EXTERNAL, DEFAULT_AMAZON_DAYS, DEFAULT_AMAZON_DOMAIN, @@ -270,7 +271,7 @@ def _get_default(key: str, fallback_default: Any = None) -> None: class MailAndPackagesFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Config flow for Mail and Packages.""" - VERSION = 8 + VERSION = CONFIG_VERSION CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL def __init__(self): diff --git a/custom_components/mail_and_packages/const.py b/custom_components/mail_and_packages/const.py index eaca05b6..8e575da0 100644 --- a/custom_components/mail_and_packages/const.py +++ b/custom_components/mail_and_packages/const.py @@ -22,6 +22,7 @@ OVERLAY = ["overlay.png", "vignette.png", "white.png"] SERVICE_UPDATE_FILE_PATH = "update_file_path" CAMERA = "cameras" +CONFIG_VERSION = 9 # Attributes ATTR_AMAZON_IMAGE = "amazon_image" diff --git a/tests/conftest.py b/tests/conftest.py index ec0b3dd6..4799b60a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -104,7 +104,7 @@ async def integration_fixture_4(hass, caplog): await hass.async_block_till_done() assert "Migrating from version 3" in caplog.text - assert "Migration complete to version 8" in caplog.text + assert "Migration complete to version 9" in caplog.text assert CONF_AMAZON_DOMAIN in entry.data diff --git a/tests/test_init.py b/tests/test_init.py index d74c5277..499fda85 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -75,7 +75,7 @@ async def test_no_path_no_sec( """Test settting up entities.""" entry = integration_no_path - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 41 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 43 entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1