1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

migrate velbus config entries (#162565)

This commit is contained in:
Maikel Punie
2026-02-10 16:14:00 +01:00
committed by GitHub
parent d2ca00ca53
commit af07631d83
4 changed files with 52 additions and 16 deletions

View File

@@ -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",

View File

@@ -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:

View File

@@ -20,7 +20,7 @@
]),
'title': 'Mock Title',
'unique_id': None,
'version': 2,
'version': 3,
}),
'modules': list([
dict({

View File

@@ -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