From 296caa90c166f81ffc6dedc85d8aea3bc989503e Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Wed, 20 May 2026 20:55:42 +0200 Subject: [PATCH] Fix exception strings in FRITZ!Box tools (#171603) --- homeassistant/components/fritz/__init__.py | 12 +++++++++--- homeassistant/components/fritz/strings.json | 9 ++++++--- tests/components/fritz/test_init.py | 10 ++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/fritz/__init__.py b/homeassistant/components/fritz/__init__.py index 4a691e70231f..74da4a88120d 100644 --- a/homeassistant/components/fritz/__init__.py +++ b/homeassistant/components/fritz/__init__.py @@ -61,14 +61,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: FritzConfigEntry) -> boo except FRITZ_AUTH_EXCEPTIONS as ex: raise ConfigEntryAuthFailed from ex except FRITZ_EXCEPTIONS as ex: - raise ConfigEntryNotReady from ex + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="error_connecting", + translation_placeholders={"error": str(ex)}, + ) from ex if ( "X_AVM-DE_UPnP1" in avm_wrapper.connection.services and not (await avm_wrapper.async_get_upnp_configuration())["NewEnable"] ): - # pylint: disable-next=home-assistant-exception-not-translated - raise ConfigEntryAuthFailed("Missing UPnP configuration") + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="error_upnp_disabled", + ) await avm_wrapper.async_config_entry_first_refresh() diff --git a/homeassistant/components/fritz/strings.json b/homeassistant/components/fritz/strings.json index 0ff85b8d5c80..fb269118aa23 100644 --- a/homeassistant/components/fritz/strings.json +++ b/homeassistant/components/fritz/strings.json @@ -185,12 +185,18 @@ "config_entry_not_found": { "message": "Failed to perform action \"{service}\". Config entry for target not found" }, + "error_connecting": { + "message": "Error connecting to the FRITZ!Box: {error}" + }, "error_parse_device_info": { "message": "Error parsing device info. Please check the system event log of your FRITZ!Box for malformed data and clear the event list." }, "error_refresh_hosts_info": { "message": "Error refreshing hosts info" }, + "error_upnp_disabled": { + "message": "UPnP is disabled on the FRITZ!Box. Please enable UPnP to use this integration." + }, "service_dial_failed": { "message": "Failed to dial, check if the click to dial service of the FRITZ!Box is activated" }, @@ -200,9 +206,6 @@ "service_parameter_unknown": { "message": "Action or parameter unknown" }, - "unable_to_connect": { - "message": "Unable to establish a connection" - }, "update_failed": { "message": "Error while updating the data: {error}" } diff --git a/tests/components/fritz/test_init.py b/tests/components/fritz/test_init.py index 0e4af3740107..ac008417ca19 100644 --- a/tests/components/fritz/test_init.py +++ b/tests/components/fritz/test_init.py @@ -115,6 +115,8 @@ async def test_setup_fail(hass: HomeAssistant, error) -> None: await hass.async_block_till_done() assert entry.state is ConfigEntryState.SETUP_RETRY + assert entry.state.recoverable is True + assert entry.error_reason_translation_key == "error_connecting" async def test_setup_fail_parse_error(hass: HomeAssistant, fc_class_mock) -> None: @@ -138,7 +140,6 @@ async def test_setup_fail_parse_error(hass: HomeAssistant, fc_class_mock) -> Non async def test_upnp_missing( hass: HomeAssistant, - caplog: pytest.LogCaptureFixture, fc_class_mock, fh_class_mock, fs_class_mock, @@ -157,12 +158,9 @@ async def test_upnp_missing( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert entry.state is ConfigEntryState.SETUP_ERROR + assert entry.state is ConfigEntryState.SETUP_RETRY assert entry.state.recoverable is True - assert ( - "Config entry 'Mock Title' for fritz integration" - " could not authenticate: Missing UPnP configuration" in caplog.text - ) + assert entry.error_reason_translation_key == "error_upnp_disabled" async def test_execute_action_while_shutdown(