Skip to content

Commit

Permalink
fix: add configuration migration for for latest version (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Nov 14, 2024
1 parent 10f3817 commit b866f6b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions custom_components/mail_and_packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CONF_IMAP_TIMEOUT,
CONF_PATH,
CONF_SCAN_INTERVAL,
CONF_STORAGE,
CONF_VERIFY_SSL,
CONFIG_VER,
COORDINATOR,
Expand Down Expand Up @@ -162,6 +163,11 @@ async def async_migrate_entry(hass, config_entry):
if CONF_AMAZON_DOMAIN not in updated_config:
updated_config[CONF_AMAZON_DOMAIN] = "amazon.com"

if version < 10:
# Add default for image storage config
if CONF_STORAGE not in updated_config:
updated_config[CONF_STORAGE] = "custom_components/mail_and_packages/images/"

if CONF_PATH not in updated_config:
updated_config[CONF_PATH] = "custom_components/mail_and_packages/images/"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OVERLAY = ["overlay.png", "vignette.png", "white.png"]
SERVICE_UPDATE_FILE_PATH = "update_file_path"
CAMERA = "cameras"
CONFIG_VER = 9
CONFIG_VER = 10

# Attributes
ATTR_AMAZON_IMAGE = "amazon_image"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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 9" in caplog.text
assert "Migration complete to version 10" in caplog.text

assert CONF_AMAZON_DOMAIN in entry.data

Expand Down
2 changes: 1 addition & 1 deletion tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
"zpackages_transit",
],
"scan_interval": 20,
"storage": "custom_components/mail_and_packages/images/",
"username": "user@fake.email",
"verify_ssl": False,
}
Expand Down Expand Up @@ -922,5 +923,4 @@
"scan_interval": 20,
"username": "user@fake.email",
"verify_ssl": False,
"storage": "custom_components/mail_and_packages/images/",
}
1 change: 1 addition & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async def test_binary_sensor_mail_delivered(
domain=DOMAIN,
title="imap.test.email",
data=FAKE_CONFIG_DATA_USPS_DELIVERED,
version=9,
)

entry.add_to_hass(hass)
Expand Down

0 comments on commit b866f6b

Please sign in to comment.