diff --git a/homeassistant/components/uptimerobot/__init__.py b/homeassistant/components/uptimerobot/__init__.py index 96ffbf795d333..b88f3b60fbcb8 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 @@ -15,9 +15,9 @@ 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( - "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..7a4abce09c910 100644 --- a/homeassistant/components/uptimerobot/coordinator.py +++ b/homeassistant/components/uptimerobot/coordinator.py @@ -48,11 +48,16 @@ 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(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_generic_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..93b764c4feb32 100644 --- a/homeassistant/components/uptimerobot/strings.json +++ b/homeassistant/components/uptimerobot/strings.json @@ -57,7 +57,16 @@ } }, "exceptions": { - "api_exception": { + "api_authentication_exception": { + "message": "API authentication failed, please check your API key" + }, + "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_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] 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" }