diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index ca6bad062246..6805e9327689 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -143,16 +143,6 @@ async def async_migrate_entry( "Migrating from version %s.%s", config_entry.version, config_entry.minor_version ) - # This is the config entry migration for adding the new program selection - # migrate from 1.x to 2.1 - if config_entry.version < 2: - # clean the velbusCache - cache_path = hass.config.path( - STORAGE_DIR, f"velbuscache-{config_entry.entry_id}/" - ) - if os.path.isdir(cache_path): - await hass.async_add_executor_job(shutil.rmtree, cache_path) - # This is the config entry migration for swapping the usb unique id to the serial number # migrate from 2.1 to 2.2 if ( @@ -166,8 +156,20 @@ async def async_migrate_entry( if len(parts) == 4: hass.config_entries.async_update_entry(config_entry, unique_id=parts[1]) + # This is the config entry migration for adding the new program selection + # migrate from < 2 to 2.1 + # This is the config entry migration for adding the new properties + # migrate from < 3 to 3.2 + if config_entry.version < 3: + # clean the velbusCache + cache_path = hass.config.path( + STORAGE_DIR, f"velbuscache-{config_entry.entry_id}/" + ) + if os.path.isdir(cache_path): + await hass.async_add_executor_job(shutil.rmtree, cache_path) + # update the config entry - hass.config_entries.async_update_entry(config_entry, version=2, minor_version=2) + hass.config_entries.async_update_entry(config_entry, version=3, minor_version=2) _LOGGER.error( "Migration to version %s.%s successful", diff --git a/homeassistant/components/velbus/config_flow.py b/homeassistant/components/velbus/config_flow.py index a413a41a1271..e43ad364e841 100644 --- a/homeassistant/components/velbus/config_flow.py +++ b/homeassistant/components/velbus/config_flow.py @@ -36,7 +36,7 @@ class InvalidVlpFile(HomeAssistantError): class VelbusConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow.""" - VERSION = 2 + VERSION = 3 MINOR_VERSION = 2 def __init__(self) -> None: diff --git a/tests/components/velbus/snapshots/test_diagnostics.ambr b/tests/components/velbus/snapshots/test_diagnostics.ambr index a280bf4c9c2f..6667c8a35086 100644 --- a/tests/components/velbus/snapshots/test_diagnostics.ambr +++ b/tests/components/velbus/snapshots/test_diagnostics.ambr @@ -20,7 +20,7 @@ ]), 'title': 'Mock Title', 'unique_id': None, - 'version': 2, + 'version': 3, }), 'modules': list([ dict({ diff --git a/tests/components/velbus/test_init.py b/tests/components/velbus/test_init.py index fc9046f977fd..246f2aa8c17f 100644 --- a/tests/components/velbus/test_init.py +++ b/tests/components/velbus/test_init.py @@ -114,11 +114,45 @@ async def test_migrate_config_entry( entry.add_to_hass(hass) # test in case we do not have a cache - with patch("os.path.isdir", return_value=True), patch("shutil.rmtree"): + with ( + patch("os.path.isdir", return_value=True), + patch("shutil.rmtree") as mock_rmtree, + ): await hass.config_entries.async_setup(entry.entry_id) assert dict(entry.data) == legacy_config - assert entry.version == 2 + assert entry.version == 3 assert entry.minor_version == 2 + mock_rmtree.assert_called_once() + + +async def test_migrate_config_entry_32( + hass: HomeAssistant, + controller: MagicMock, +) -> None: + """Test successful migration of entry data.""" + legacy_config = {CONF_NAME: "fake_name", CONF_PORT: "1.2.3.4:5678"} + entry = MockConfigEntry( + domain=DOMAIN, + unique_id="my own id", + data=legacy_config, + version=2, + minor_version=2, + ) + assert entry.version == 2 + assert entry.minor_version == 2 + + entry.add_to_hass(hass) + + # test in case we do not have a cache + with ( + patch("os.path.isdir", return_value=True), + patch("shutil.rmtree") as mock_rmtree, + ): + await hass.config_entries.async_setup(entry.entry_id) + assert dict(entry.data) == legacy_config + assert entry.version == 3 + assert entry.minor_version == 2 + mock_rmtree.assert_called_once() @pytest.mark.parametrize( @@ -141,7 +175,7 @@ async def test_migrate_config_entry_unique_id( await hass.config_entries.async_setup(entry.entry_id) assert entry.unique_id == expected - assert entry.version == 2 + assert entry.version == 3 assert entry.minor_version == 2