Tankerkoenig handle api errors config flow by mib1185 · Pull Request #185719 · home-assistant/core · GitHub
Skip to content

Tankerkoenig handle api errors config flow - #185719

Merged
frenck merged 4 commits into
home-assistant:devfrom
mib1185:tankerkoenig-handle-api-errors-config-flow
Oct 10, 2026
Merged

frenck merged 4 commits into
home-assistant:devfrom
mib1185:tankerkoenig-handle-api-errors-config-flow

Conversation

@mib1185

@mib1185 mib1185 commented Oct 10, 2026

Copy link
Copy Markdown
Member

Proposed change

The Tankerkoenig config flow only caught TankerkoenigInvalidKeyError. Any other API problem crashed the flow with a "500 Internal Server Error", for example a connection error, timeout, rate limit, unexpected API error message or non-JSON maintenance page. This affected the user, reauth and options flows.

  • The user and reauth steps now catch TankerkoenigError and show a cannot_connect error, so the user can try again.
  • The options flow aborts with cannot_connect, because it needs the station list from the API to build its form.
  • Since aiotankerkoenig 0.5.5 (Bump aiotankerkoenig to 0.5.5 #185714), key related messages like "Key existiert nicht oder ist deaktiviert" raise TankerkoenigInvalidKeyError, which the flow shows as invalid_auth. The API sends this message for valid keys too while its authentication service is down. So the invalid_auth text now says the service may be temporarily unavailable.

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.10.2 milestone Oct 10, 2026
Copilot AI balanced review requested due to automatic review settings October 10, 2026 20:09
@mib1185
mib1185 requested a review from jpbede as a code owner October 10, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@home-assistant

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

mib1185 and others added 4 commits October 10, 2026 20:21
Catch all aiotankerkoenig errors during the user, reauth and options
flows and show a cannot_connect error (or abort the options flow)
instead of letting the flow fail with an unhandled exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Qr7b4ZqWA7jSV9VE6pAbr
Feed the actual API error payloads through aiotankerkoenig to verify
that key related messages (e.g. "Key existiert nicht oder ist
deaktiviert" from the linked issue) are reported as invalid_auth and
other errors as cannot_connect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Qr7b4ZqWA7jSV9VE6pAbr
The Tankerkoenig API reports a valid key as non-existent while its
authentication service is down, so mention this possibility in the
invalid_auth error shown in the config, reauth and options flows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Qr7b4ZqWA7jSV9VE6pAbr
Parsing of the API responses is covered by the aiotankerkoenig test
suite, the config flow tests mock the library results instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Qr7b4ZqWA7jSV9VE6pAbr
@mib1185
mib1185 force-pushed the tankerkoenig-handle-api-errors-config-flow branch from 601e737 to 63e2e7f Compare October 10, 2026 20:21

@frenck frenck left a comment

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.

Oh hi there @mib1185 👋

My review notes: (this space intentionally left blank). Thanks for the pull request!

../Frenck

                       

Blogging my personal ramblings at frenck.dev

Here is a dad joke for you:

It takes guts to be an organ donor.

@frenck
frenck merged commit 6390349 into home-assistant:dev Oct 10, 2026
36 checks passed
@mib1185
mib1185 deleted the tankerkoenig-handle-api-errors-config-flow branch October 10, 2026 21:53
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot reconfigure Tankerkoenig - Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble

4 participants