Raise ConfigEntryNotReady when migration cannot reach router in freebox (#185292)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
G Johansson
2026-10-09 12:06:35 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 328086a221
commit 99397aaeb7
3 changed files with 31 additions and 5 deletions
+6 -5
View File
@@ -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()
@@ -58,5 +58,10 @@
"name": "Wi-Fi"
}
}
},
"exceptions": {
"cannot_connect": {
"message": "Failed to connect to the Freebox router at {host}"
}
}
}
+20
View File
@@ -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,