Skip to content

Commit

Permalink
fix: fix missing config for image path (#945)
Browse files Browse the repository at this point in the history
* fix: fix missing config for image path

* formatting

* fix tests
  • Loading branch information
firstof9 authored Jul 12, 2024
1 parent fa6951b commit 7b636c0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion custom_components/mail_and_packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CONF_PATH,
CONF_SCAN_INTERVAL,
CONF_VERIFY_SSL,
CONFIG_VERSION,
COORDINATOR,
DEFAULT_AMAZON_DAYS,
DOMAIN,
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion custom_components/mail_and_packages/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CONF_PATH,
CONF_SCAN_INTERVAL,
CONF_VERIFY_SSL,
CONFIG_VERSION,
DEFAULT_ALLOW_EXTERNAL,
DEFAULT_AMAZON_DAYS,
DEFAULT_AMAZON_DOMAIN,
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7b636c0

Please sign in to comment.