Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions homeassistant/components/fritz/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import re
from typing import Any, TypedDict, cast
from xml.etree.ElementTree import ParseError

from fritzconnection import FritzConnection
from fritzconnection.core.exceptions import FritzActionError
Expand All @@ -24,7 +25,7 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.dispatcher import async_dispatcher_send
Expand Down Expand Up @@ -226,7 +227,13 @@ def setup(self) -> None:
self.fritz_guest_wifi = FritzGuestWLAN(fc=self.connection)
self.fritz_status = FritzStatus(fc=self.connection)
self.fritz_call = FritzCall(fc=self.connection)
info = self.fritz_status.get_device_info()
try:
info = self.fritz_status.get_device_info()
except ParseError as ex:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="error_parse_device_info",
) from ex

_LOGGER.debug(
"gathered device info of %s %s",
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/fritz/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
"config_entry_not_found": {
"message": "Failed to perform action \"{service}\". Config entry for target not found"
},
"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."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would a user recognize malformed data?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the malformed data would look like:

26.08.25 01:28:49 IPv6-Präfix konnte nicht bezogen werden, Fehlergrund: 0 (��m1�m��m�o�m�a���a���Y�m���l�)

but even the user wouldn't recognize it in the first place, the instruction says "...and clear the event list" which will finally resolve the issue

},
"error_refresh_hosts_info": {
"message": "Error refreshing hosts info"
},
Expand Down
20 changes: 20 additions & 0 deletions tests/components/fritz/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re
from unittest.mock import patch
from xml.etree.ElementTree import ParseError

from freezegun.api import FrozenDateTimeFactory
import pytest
Expand Down Expand Up @@ -116,6 +117,25 @@ async def test_setup_fail(hass: HomeAssistant, error) -> None:
assert entry.state is ConfigEntryState.SETUP_RETRY


async def test_setup_fail_parse_error(hass: HomeAssistant, fc_class_mock) -> None:
"""Test setup failure due to parse error while fetching device data."""

entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
entry.add_to_hass(hass)

with (
patch(
"homeassistant.components.fritz.coordinator.FritzStatus.get_device_info"
) as fs_mock,
):
fs_mock.side_effect = ParseError("boom")
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert entry.state is ConfigEntryState.SETUP_RETRY
assert entry.error_reason_translation_key == "error_parse_device_info"


async def test_upnp_missing(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
Expand Down