Raise ConfigEntryError when migrating version 1 entries in toon (#185432)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
G Johansson
2026-10-09 14:49:21 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 88623057fe
commit 516d5470af
3 changed files with 31 additions and 2 deletions
+5 -1
View File
@@ -11,6 +11,7 @@ from homeassistant.const import (
Platform,
)
from homeassistant.core import CoreState, HomeAssistant
from homeassistant.exceptions import ConfigEntryError
from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.config_entry_oauth2_flow import (
OAuth2Session,
@@ -79,7 +80,10 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data={CONF_MIGRATE: entry.entry_id},
)
)
return False
raise ConfigEntryError(
translation_domain=DOMAIN,
translation_key="setup_required",
)
if entry.version == 2:
# 2 -> 2.2: Unique ID from integer to string
@@ -32,6 +32,9 @@
},
"invalid_response": {
"message": "Received an invalid response from the Toon device."
},
"setup_required": {
"message": "This configuration entry is no longer supported, complete the new Toon setup to replace it."
}
}
}
+23 -1
View File
@@ -7,7 +7,8 @@ from toonapi import Agreement, Status
from toonapi.models import ThermostatInfo
from homeassistant.components.toon import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.components.toon.const import CONF_MIGRATE
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow, device_registry as dr
from homeassistant.helpers.config_entry_oauth2_flow import (
@@ -47,6 +48,27 @@ async def test_oauth_implementation_not_available(
assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_migrate_entry_version_1(hass: HomeAssistant) -> None:
"""Test a version 1 config entry starts a new flow and fails migration."""
entry = MockConfigEntry(domain=DOMAIN, data={}, version=1)
entry.add_to_hass(hass)
with patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.MIGRATION_ERROR
assert entry.reason == (
"This configuration entry is no longer supported, complete the new Toon"
" setup to replace it"
)
mock_flow_init.assert_called_once_with(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_MIGRATE: entry.entry_id},
)
async def test_migrate_entry_minor_version_2_2(hass: HomeAssistant) -> None:
"""Test migrating a 2.1 config entry to 2.2."""
with patch("homeassistant.components.toon.async_setup_entry", return_value=True):