diff --git a/custom_components/diveracontrol/__init__.py b/custom_components/diveracontrol/__init__.py index 5be5974..7e8514e 100644 --- a/custom_components/diveracontrol/__init__.py +++ b/custom_components/diveracontrol/__init__.py @@ -187,6 +187,26 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> "Failed to remove old entity registry entries during migration" ) - # v1.2.1: no migration needed + # v1.2.1: add new base_url parameter to config entry + if VERSION == 1 and MINOR_VERSION == 2 and PATCH_VERSION == 1: + _LOGGER.info( + "Migrating config entry to version %s.%s.%s", + VERSION, + MINOR_VERSION, + PATCH_VERSION, + ) + + if D_BASE_API_URL not in config_entry.data: + _LOGGER.info("Adding base_url to existing config entry") + + hass.config_entries.async_update_entry( + config_entry, + data={ + **config_entry.data, + D_BASE_API_URL: "https://api.divera247.com", + }, + version=VERSION, + minor_version=MINOR_VERSION, + ) return True diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 8a51481..b2c5fd1 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -220,6 +220,7 @@ async def test_reconfigure( from custom_components.diveracontrol.const import ( D_UPDATE_INTERVAL_ALARM, D_UPDATE_INTERVAL_DATA, + D_BASE_API_URL, ) # Add the existing config entry to hass @@ -270,10 +271,8 @@ async def test_reconfigure( assert updated_entry.data[D_API_KEY] == new_api_key assert updated_entry.data[D_UPDATE_INTERVAL_DATA] == new_interval_data assert updated_entry.data[D_UPDATE_INTERVAL_ALARM] == new_interval_alarm - - # Properly unload the entry to clean up timers - await hass.config_entries.async_unload(mock_config_entry.entry_id) - await hass.async_block_till_done() + # Verify base_url is present from migration + assert D_BASE_API_URL in updated_entry.data async def test_reconfigure_entry_not_found(hass: HomeAssistant) -> None: