Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion homeassistant/components/fritz/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime, timedelta
import logging

from fritzconnection.core.exceptions import FritzConnectionException
from fritzconnection.lib.fritzstatus import FritzStatus
from requests.exceptions import RequestException

Expand Down Expand Up @@ -143,7 +144,7 @@ def _is_suitable_cpu_temperature(status: FritzStatus) -> bool:
"""Return whether the CPU temperature sensor is suitable."""
try:
cpu_temp = status.get_cpu_temperatures()[0]
except RequestException, IndexError:
except RequestException, IndexError, FritzConnectionException:
_LOGGER.debug("CPU temperature not supported by the device")
return False
Comment on lines 145 to 149
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

Handle CPU temperature retrieval failures consistently by also catching the same exceptions in _retrieve_cpu_temperature_state (e.g., IndexError / FritzConnectionException) that _is_suitable_cpu_temperature treats as "not supported", so an empty/unauthorized response during later updates can’t bubble up and break coordinator updates.

Copilot uses AI. Check for mistakes.
if cpu_temp == 0:
Expand Down
7 changes: 6 additions & 1 deletion tests/components/fritz/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
@pytest.mark.parametrize(
("side_effect", "return_values"),
[(RequestException("boom"), None), (None, [0, 0, 0]), (None, [])],
[
(RequestException("boom"), None),
(None, [0, 0, 0]),
(None, []),
(FritzConnectionException("boom"), None),
],
Comment on lines 118 to +125
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

Add a parametrized case for the reported FritzAuthorizationError (HTTP 403) in addition to FritzConnectionException so the test directly exercises the exact failure mode described in the issue.

Copilot uses AI. Check for mistakes.
)
async def test_sensor_cpu_temp_not_supported(
hass: HomeAssistant,
Expand Down Expand Up @@ -145,7 +150,7 @@
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)

Check failure on line 153 in tests/components/fritz/test_sensor.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.14.4 (fritz)

test_sensor_cpu_temp_not_supported[side_effect3-None] AssertionError: assert [+ received] == [- snapshot] Snapshot 'test_sensor_cpu_temp_not_supported[side_effect3-None][sensor.mock_title_external_ip-entry]' does not exist! + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': <ANY>, + 'config_subentry_id': <ANY>, + 'device_class': None, + 'device_id': <ANY>, + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.mock_title_external_ip', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': <ANY>, + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'External IP', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'External IP', + 'platform': 'fritz', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'external_ip', + 'unique_id': '1CED6F123411-external_ip', + 'unit_of_measurement': None, + })
assert not entity_registry.async_is_registered(
"sensor.mock_title_cpu_temperature"
)
Loading