From 99397aaeb7eb1b0718d77a080366cc23a35f26f2 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Fri, 9 Oct 2026 12:06:35 +0200 Subject: [PATCH] Raise ConfigEntryNotReady when migration cannot reach router in freebox (#185292) Co-authored-by: Claude Opus 5.5 --- homeassistant/components/freebox/__init__.py | 11 +++++----- homeassistant/components/freebox/strings.json | 5 +++++ tests/components/freebox/test_init.py | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/freebox/__init__.py b/homeassistant/components/freebox/__init__.py index 6b761519f884..cfae13f2862c 100644 --- a/homeassistant/components/freebox/__init__.py +++ b/homeassistant/components/freebox/__init__.py @@ -38,11 +38,12 @@ async def async_migrate_entry(hass: HomeAssistant, entry: FreeboxConfigEntry) -> try: await api.open(entry.data[CONF_HOST], entry.data[CONF_PORT]) freebox_config = await api.system.get_config() - except HttpRequestError: - _LOGGER.warning( - "Unable to migrate Freebox entry to version 2: cannot reach the router" - ) - return False + except HttpRequestError as err: + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="cannot_connect", + translation_placeholders={"host": entry.data[CONF_HOST]}, + ) from err finally: await api.close() diff --git a/homeassistant/components/freebox/strings.json b/homeassistant/components/freebox/strings.json index 5fde95a937f0..45cf6d5f789a 100644 --- a/homeassistant/components/freebox/strings.json +++ b/homeassistant/components/freebox/strings.json @@ -58,5 +58,10 @@ "name": "Wi-Fi" } } + }, + "exceptions": { + "cannot_connect": { + "message": "Failed to connect to the Freebox router at {host}" + } } } diff --git a/tests/components/freebox/test_init.py b/tests/components/freebox/test_init.py index 4ff84db92fe5..f3e19ef66698 100644 --- a/tests/components/freebox/test_init.py +++ b/tests/components/freebox/test_init.py @@ -206,6 +206,26 @@ async def test_unique_id_migration( ) +async def test_unique_id_migration_cannot_connect( + hass: HomeAssistant, router: Mock +) -> None: + """Test migration is retried when the router cannot be reached.""" + router.return_value.open.side_effect = HttpRequestError("Boom") + entry = MockConfigEntry( + domain=DOMAIN, + data={CONF_HOST: MOCK_HOST, CONF_PORT: MOCK_PORT}, + unique_id=MOCK_HOST, + ) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert entry.state is ConfigEntryState.SETUP_RETRY + assert entry.reason == f"Failed to connect to the Freebox router at {MOCK_HOST}" + assert entry.version == 1 + + @pytest.mark.usefixtures("router") async def test_home_device_via_device( hass: HomeAssistant,