Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/uptimerobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
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


async def async_setup_entry(hass: HomeAssistant, entry: UptimeRobotConfigEntry) -> bool:
"""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",
)
Comment thread
chemelli74 marked this conversation as resolved.
uptime_robot_api = UptimeRobot(key, async_get_clientsession(hass))

Expand Down
13 changes: 9 additions & 4 deletions homeassistant/components/uptimerobot/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Comment thread
chemelli74 marked this conversation as resolved.
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
Comment on lines +56 to +60

if TYPE_CHECKING:
assert isinstance(response.data, list)
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/uptimerobot/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/uptimerobot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Comment thread
frenck marked this conversation as resolved.
) from exception

Expand Down
5 changes: 4 additions & 1 deletion tests/components/uptimerobot/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Comment thread
frenck marked this conversation as resolved.
Comment on lines 47 to +51

assert len(flows) == 1
flow = flows[0]
Expand Down
4 changes: 2 additions & 2 deletions tests/components/uptimerobot/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Comment thread
frenck marked this conversation as resolved.
Comment on lines 160 to 164
Expand Down Expand Up @@ -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"
}
Comment thread
frenck marked this conversation as resolved.
Comment on lines 188 to 192
Expand Down