Skip to content

Fix hardcoded exception strings in uptimerobot#171744

Merged
frenck merged 4 commits into
home-assistant:devfrom
chemelli74:chemelli74-uptimerobot-strings
May 22, 2026
Merged

Fix hardcoded exception strings in uptimerobot#171744
frenck merged 4 commits into
home-assistant:devfrom
chemelli74:chemelli74-uptimerobot-strings

Conversation

@chemelli74
Copy link
Copy Markdown
Contributor

@chemelli74 chemelli74 commented May 21, 2026

Proposed change

Fix hardcoded exception strings in uptimerobot, found in home-assistant/epics#71

Note: Used the same message already used in the integration. Will need a tweak in future: home-assistant/architecture#1397

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:

@home-assistant
Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of uptimerobot 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 uptimerobot 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 updates the UptimeRobot integration to use translated exception metadata (via translation_domain / translation_key) instead of hardcoded exception strings, and adjusts tests accordingly.

Changes:

  • Add new exception message keys under exceptions in homeassistant/components/uptimerobot/strings.json.
  • Raise ConfigEntryAuthFailed / UpdateFailed using translation metadata in the coordinator and setup entry.
  • Update the setup/reauth test to assert the new (translated) config entry failure reason.

Reviewed changes

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

File Description
homeassistant/components/uptimerobot/coordinator.py Switches auth/update exceptions to translated exceptions; currently introduces a misleading translation key/placeholder for update failures.
homeassistant/components/uptimerobot/__init__.py Switches wrong-API-key-type setup failure to translated exception metadata.
homeassistant/components/uptimerobot/strings.json Adds new exceptions.* messages used by the translated exceptions.
tests/components/uptimerobot/test_init.py Updates assertions to match the new auth-failure reason text.

Comment on lines +58 to +62
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="api_exception",
translation_placeholders={"error": "Generic UptimeRobot exception"},
) from exception
Comment thread homeassistant/components/uptimerobot/coordinator.py
Comment thread homeassistant/components/uptimerobot/__init__.py
Copy link
Copy Markdown
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

We can remove the pylint exceptions

@home-assistant home-assistant Bot marked this pull request as draft May 21, 2026 17:00
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Comment thread homeassistant/components/uptimerobot/__init__.py Outdated
Comment thread homeassistant/components/uptimerobot/coordinator.py Outdated
raise UpdateFailed(exception) from exception
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="api_exception",
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.

The string for "api_exception" is specific for turning on/off monitoring; it is not suitable for use here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh indeed

Copilot AI review requested due to automatic review settings May 21, 2026 20:43
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

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

Comment thread homeassistant/components/uptimerobot/coordinator.py Outdated
Comment thread homeassistant/components/uptimerobot/utils.py
Comment thread tests/components/uptimerobot/test_init.py
Comment thread tests/components/uptimerobot/test_switch.py
Comment thread tests/components/uptimerobot/test_switch.py
@chemelli74 chemelli74 marked this pull request as ready for review May 21, 2026 20:49
Copilot AI review requested due to automatic review settings May 21, 2026 20:49
@home-assistant home-assistant Bot requested a review from joostlek May 21, 2026 20:49
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

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

translation_domain=DOMAIN,
translation_key="api_exception",
translation_key="api_switch_exception",
translation_placeholders={"error": "Generic UptimeRobot exception"},
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="api_generic_exception",
translation_placeholders={"error": "Generic UptimeRobot exception"},
Comment on lines 47 to +51
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
assert mock_config_entry.reason == "could not authenticate"
assert (
mock_config_entry.reason
== "API authentication failed, please check your API key"
)
Comment on lines 160 to 164
assert exc_info.value.translation_domain == "uptimerobot"
assert exc_info.value.translation_key == "api_exception"
assert exc_info.value.translation_key == "api_switch_exception"
assert exc_info.value.translation_placeholders == {
"error": "Generic UptimeRobot exception"
}
Comment on lines 188 to 192
assert exc_info.value.translation_domain == "uptimerobot"
assert exc_info.value.translation_key == "api_exception"
assert exc_info.value.translation_key == "api_switch_exception"
assert exc_info.value.translation_placeholders == {
"error": "Generic UptimeRobot exception"
}
Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @chemelli74 👍

../Frenck

                       

Blogging my personal ramblings at frenck.dev

@frenck frenck dismissed joostlek’s stale review May 22, 2026 08:33

Comments addressed

@frenck frenck merged commit a868ea4 into home-assistant:dev May 22, 2026
33 checks passed
@chemelli74 chemelli74 deleted the chemelli74-uptimerobot-strings branch May 22, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix hardcoded exception strings in uptimerobot

5 participants