From 516d5470aff79d1214a65e871c5fca06dfb012cd Mon Sep 17 00:00:00 2001 From: G Johansson Date: Fri, 9 Oct 2026 14:49:21 +0200 Subject: [PATCH] Raise ConfigEntryError when migrating version 1 entries in toon (#185432) Co-authored-by: Claude Opus 5.5 --- homeassistant/components/toon/__init__.py | 6 +++++- homeassistant/components/toon/strings.json | 3 +++ tests/components/toon/test_init.py | 24 +++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/toon/__init__.py b/homeassistant/components/toon/__init__.py index 773543b242c0..d39381caf5b0 100644 --- a/homeassistant/components/toon/__init__.py +++ b/homeassistant/components/toon/__init__.py @@ -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 diff --git a/homeassistant/components/toon/strings.json b/homeassistant/components/toon/strings.json index 8fd0a1c6daeb..4ae0face24c0 100644 --- a/homeassistant/components/toon/strings.json +++ b/homeassistant/components/toon/strings.json @@ -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." } } } diff --git a/tests/components/toon/test_init.py b/tests/components/toon/test_init.py index 85a875707037..0aec5a89809f 100644 --- a/tests/components/toon/test_init.py +++ b/tests/components/toon/test_init.py @@ -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):