From 4d5ac472a6a8689276701c315a716308ec945815 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 21 May 2026 15:40:33 +0000 Subject: [PATCH 1/4] Fix hardcoded exception strings in uptimerobot --- homeassistant/components/uptimerobot/__init__.py | 5 +++-- homeassistant/components/uptimerobot/coordinator.py | 11 +++++++++-- homeassistant/components/uptimerobot/strings.json | 6 ++++++ tests/components/uptimerobot/test_init.py | 5 ++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/uptimerobot/__init__.py b/homeassistant/components/uptimerobot/__init__.py index 96ffbf795d333..a805770f793e8 100644 --- a/homeassistant/components/uptimerobot/__init__.py +++ b/homeassistant/components/uptimerobot/__init__.py @@ -7,7 +7,7 @@ from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.aiohttp_client import async_get_clientsession -from .const import PLATFORMS +from .const import DOMAIN, PLATFORMS from .coordinator import UptimeRobotConfigEntry, UptimeRobotDataUpdateCoordinator @@ -17,7 +17,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: UptimeRobotConfigEntry) if key.startswith(("ur", "m")): # pylint: disable-next=home-assistant-exception-not-translated raise ConfigEntryAuthFailed( - "Wrong API key type detected, use the 'main' API key" + translation_domain=DOMAIN, + translation_key="api_key_wrong_type", ) uptime_robot_api = UptimeRobot(key, async_get_clientsession(hass)) diff --git a/homeassistant/components/uptimerobot/coordinator.py b/homeassistant/components/uptimerobot/coordinator.py index f4666b1a6c45a..d2d4bd1369c9f 100644 --- a/homeassistant/components/uptimerobot/coordinator.py +++ b/homeassistant/components/uptimerobot/coordinator.py @@ -49,10 +49,17 @@ async def _async_update_data(self) -> dict[int, UptimeRobotMonitor]: response = await self.api.async_get_monitors() except UptimeRobotAuthenticationException as exception: # pylint: disable-next=home-assistant-exception-not-translated - raise ConfigEntryAuthFailed(exception) from exception + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="api_authentication_exception", + ) from exception except UptimeRobotException as exception: # pylint: disable-next=home-assistant-exception-not-translated - raise UpdateFailed(exception) from exception + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="api_exception", + translation_placeholders={"error": "Generic UptimeRobot exception"}, + ) from exception if TYPE_CHECKING: assert isinstance(response.data, list) diff --git a/homeassistant/components/uptimerobot/strings.json b/homeassistant/components/uptimerobot/strings.json index 64e73fd39f10c..6ea8c510041fa 100644 --- a/homeassistant/components/uptimerobot/strings.json +++ b/homeassistant/components/uptimerobot/strings.json @@ -57,8 +57,14 @@ } }, "exceptions": { + "api_authentication_exception": { + "message": "API authentication failed, please check your API key" + }, "api_exception": { "message": "Could not turn on/off monitoring: {error}" + }, + "api_key_wrong_type": { + "message": "Wrong API key type detected, use the 'main' API key" } } } diff --git a/tests/components/uptimerobot/test_init.py b/tests/components/uptimerobot/test_init.py index 101c1d86af278..ca6f054f6871b 100644 --- a/tests/components/uptimerobot/test_init.py +++ b/tests/components/uptimerobot/test_init.py @@ -45,7 +45,10 @@ async def test_reauthentication_trigger_in_setup( flows = hass.config_entries.flow.async_progress() 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" + ) assert len(flows) == 1 flow = flows[0] From 5dd5bce902a578bed50d38be0ec58955dc153eb3 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 21 May 2026 20:10:06 +0000 Subject: [PATCH 2/4] cleanup --- homeassistant/components/uptimerobot/__init__.py | 1 - homeassistant/components/uptimerobot/coordinator.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/homeassistant/components/uptimerobot/__init__.py b/homeassistant/components/uptimerobot/__init__.py index a805770f793e8..b88f3b60fbcb8 100644 --- a/homeassistant/components/uptimerobot/__init__.py +++ b/homeassistant/components/uptimerobot/__init__.py @@ -15,7 +15,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: UptimeRobotConfigEntry) """Set up UptimeRobot from a config entry.""" key: str = entry.data[CONF_API_KEY] if key.startswith(("ur", "m")): - # pylint: disable-next=home-assistant-exception-not-translated raise ConfigEntryAuthFailed( translation_domain=DOMAIN, translation_key="api_key_wrong_type", diff --git a/homeassistant/components/uptimerobot/coordinator.py b/homeassistant/components/uptimerobot/coordinator.py index d2d4bd1369c9f..a39351a011538 100644 --- a/homeassistant/components/uptimerobot/coordinator.py +++ b/homeassistant/components/uptimerobot/coordinator.py @@ -48,13 +48,11 @@ async def _async_update_data(self) -> dict[int, UptimeRobotMonitor]: try: response = await self.api.async_get_monitors() except UptimeRobotAuthenticationException as exception: - # pylint: disable-next=home-assistant-exception-not-translated raise ConfigEntryAuthFailed( translation_domain=DOMAIN, translation_key="api_authentication_exception", ) from exception except UptimeRobotException as exception: - # pylint: disable-next=home-assistant-exception-not-translated raise UpdateFailed( translation_domain=DOMAIN, translation_key="api_exception", From f5fb0c002e09a5a80fe6094822330403deb2837f Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 21 May 2026 20:41:47 +0000 Subject: [PATCH 3/4] improve strings --- homeassistant/components/uptimerobot/strings.json | 7 +++++-- homeassistant/components/uptimerobot/utils.py | 2 +- tests/components/uptimerobot/test_switch.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/uptimerobot/strings.json b/homeassistant/components/uptimerobot/strings.json index 6ea8c510041fa..93b764c4feb32 100644 --- a/homeassistant/components/uptimerobot/strings.json +++ b/homeassistant/components/uptimerobot/strings.json @@ -60,11 +60,14 @@ "api_authentication_exception": { "message": "API authentication failed, please check your API key" }, - "api_exception": { - "message": "Could not turn on/off monitoring: {error}" + "api_generic_exception": { + "message": "API error: {error}" }, "api_key_wrong_type": { "message": "Wrong API key type detected, use the 'main' API key" + }, + "api_switch_exception": { + "message": "Could not turn on/off monitoring: {error}" } } } diff --git a/homeassistant/components/uptimerobot/utils.py b/homeassistant/components/uptimerobot/utils.py index f0ae42ac9acce..eae44544e4a3b 100644 --- a/homeassistant/components/uptimerobot/utils.py +++ b/homeassistant/components/uptimerobot/utils.py @@ -33,7 +33,7 @@ async def cmd_wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None: except UptimeRobotException as exception: raise HomeAssistantError( translation_domain=DOMAIN, - translation_key="api_exception", + translation_key="api_switch_exception", translation_placeholders={"error": "Generic UptimeRobot exception"}, ) from exception diff --git a/tests/components/uptimerobot/test_switch.py b/tests/components/uptimerobot/test_switch.py index 4974fe92f9903..8d745267c478b 100644 --- a/tests/components/uptimerobot/test_switch.py +++ b/tests/components/uptimerobot/test_switch.py @@ -158,7 +158,7 @@ async def test_action_execution_failure(hass: HomeAssistant) -> None: ) 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" } @@ -186,7 +186,7 @@ async def test_switch_api_failure(hass: HomeAssistant) -> None: ) 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" } From 7af002f13a7660f9faac07e15f7dd72799df5102 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Thu, 21 May 2026 20:48:37 +0000 Subject: [PATCH 4/4] fix --- homeassistant/components/uptimerobot/coordinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/uptimerobot/coordinator.py b/homeassistant/components/uptimerobot/coordinator.py index a39351a011538..7a4abce09c910 100644 --- a/homeassistant/components/uptimerobot/coordinator.py +++ b/homeassistant/components/uptimerobot/coordinator.py @@ -55,7 +55,7 @@ async def _async_update_data(self) -> dict[int, UptimeRobotMonitor]: except UptimeRobotException as exception: raise UpdateFailed( translation_domain=DOMAIN, - translation_key="api_exception", + translation_key="api_generic_exception", translation_placeholders={"error": "Generic UptimeRobot exception"}, ) from exception