diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index feeb9c6c2b8d..8903d62ed78d 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -166,8 +166,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: TelegramBotConfigEntry) try: await bot.get_me() except InvalidToken as err: - # pylint: disable-next=home-assistant-exception-not-translated - raise ConfigEntryAuthFailed("Invalid API token for Telegram Bot.") from err + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="invalid_api_key", + ) from err except TelegramError as err: # Do not let the message through: the Telegram API URL embeds the bot # token, and library errors quote that URL. diff --git a/homeassistant/components/telegram_bot/strings.json b/homeassistant/components/telegram_bot/strings.json index 439ee965ad09..4ff98c7247c3 100644 --- a/homeassistant/components/telegram_bot/strings.json +++ b/homeassistant/components/telegram_bot/strings.json @@ -198,6 +198,9 @@ "failed_to_load_url": { "message": "Failed to load URL: {error}" }, + "invalid_api_key": { + "message": "The Telegram bot API token is invalid." + }, "invalid_chat_ids": { "message": "Invalid chat IDs: {chat_ids}. Please configure the chat IDs for {bot_name}." }, diff --git a/tests/components/telegram_bot/test_telegram_bot.py b/tests/components/telegram_bot/test_telegram_bot.py index 0ecea74df54e..243d21926125 100644 --- a/tests/components/telegram_bot/test_telegram_bot.py +++ b/tests/components/telegram_bot/test_telegram_bot.py @@ -1476,6 +1476,7 @@ async def test_async_setup_entry_failed( await hass.async_block_till_done() assert mock_broadcast_config_entry.state is ConfigEntryState.SETUP_ERROR + assert mock_broadcast_config_entry.error_reason_translation_key == "invalid_api_key" async def test_answer_callback_query(