Skip to content

Fix detection of CPU temperature sensor support on olde FRITZ!Box models#169620

Open
mib1185 wants to merge 2 commits intodevfrom
fritz/do-not-add-cpu-temp-sensor-on-older-models
Open

Fix detection of CPU temperature sensor support on olde FRITZ!Box models#169620
mib1185 wants to merge 2 commits intodevfrom
fritz/do-not-add-cpu-temp-sensor-on-older-models

Conversation

@mib1185
Copy link
Copy Markdown
Member

@mib1185 mib1185 commented May 1, 2026

Proposed change

Older models seems to not support these experimental and undocumented http api and those causes FritzConnectionException errors like FritzAuthorizationError

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@mib1185 mib1185 added this to the 2026.5.0 milestone May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 18:41
@mib1185 mib1185 requested a review from chemelli74 as a code owner May 1, 2026 18:41
@home-assistant home-assistant Bot added bugfix cla-signed has-tests integration: fritz small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage labels May 1, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 1, 2026

Hey there @AaronDavidSchneider, @chemelli74, mind taking a look at this pull request as it has been labeled with an integration (fritz) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of fritz can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign fritz Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent the FRITZ! integration from attempting to set up the CPU temperature sensor on older FRITZ!Box models that don’t support the (experimental/undocumented) HTTP endpoint and can raise fritzconnection exceptions (e.g., HTTP 403).

Changes:

  • Extend CPU temperature sensor suitability detection to treat FritzConnectionException as “not supported”.
  • Extend the existing CPU temperature “not supported” test matrix to include a fritzconnection exception case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
homeassistant/components/fritz/sensor.py Treat fritzconnection connection exceptions as “CPU temperature not supported” during suitability probing.
tests/components/fritz/test_sensor.py Add an additional parametrized test case for CPU temp support detection when fritzconnection raises.

Comment on lines 145 to 149
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
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.
Comment on lines 118 to +125
@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),
],
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.
@chemelli74
Copy link
Copy Markdown
Contributor

I'm not sure FritzConnectionException is a good idea; what if it's a real connection issue and not just a old firmware ?

Are we sure there is no endpoint to get this info from ? Users reported temperature is shown in Fritzbox UI.

@mib1185
Copy link
Copy Markdown
Member Author

mib1185 commented May 2, 2026

I'm not sure FritzConnectionException is a good idea; what if it's a real connection issue and not just a old firmware ?

I choose this wide exception on purpose as this API itself is not documented nor obversely consistent across the different FRITZ!OS versions, those it can cause also other exceptions. As this sensor is meanwhile also disabled by default, I think the chance of hitting a real connection issue exactly with this api call, but not the other previous and subsequent api calls for the other "is suitable" checks is quiet low.

Are we sure there is no endpoint to get this info from ? Users reported temperature is shown in Fritzbox UI.

Yeah, it would need much more reverse engineering efforts to check this out across all the possible FRITZ!Box model and FRITZ!OS version combinations (as said above, this API is not documented)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix by-code-owner cla-signed has-tests integration: fritz Quality Scale: gold small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error adding entity sensor.fritz_box_7412_ui_cpu_temperatur

3 participants