From d907e4c10b9c22643b846df96c05e554338d5e20 Mon Sep 17 00:00:00 2001 From: hanwg Date: Fri, 6 Jun 2025 22:00:48 +0800 Subject: [PATCH] Handle error in setup_entry for Telegram Bot (#146242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * handle error in setup_entry * Update homeassistant/components/telegram_bot/__init__.py Co-authored-by: Abílio Costa --------- Co-authored-by: Abílio Costa --- homeassistant/components/telegram_bot/__init__.py | 10 ++++++++-- homeassistant/components/telegram_bot/config_flow.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index fdf17023d39..d4e3e2afd07 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -8,7 +8,7 @@ from types import ModuleType from typing import Any from telegram import Bot -from telegram.error import InvalidToken +from telegram.error import InvalidToken, TelegramError import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT @@ -26,7 +26,11 @@ from homeassistant.core import ( ServiceResponse, SupportsResponse, ) -from homeassistant.exceptions import ConfigEntryAuthFailed, ServiceValidationError +from homeassistant.exceptions import ( + ConfigEntryAuthFailed, + ConfigEntryNotReady, + ServiceValidationError, +) from homeassistant.helpers import config_validation as cv from homeassistant.helpers.typing import ConfigType @@ -418,6 +422,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: TelegramBotConfigEntry) await bot.get_me() except InvalidToken as err: raise ConfigEntryAuthFailed("Invalid API token for Telegram Bot.") from err + except TelegramError as err: + raise ConfigEntryNotReady from err p_type: str = entry.data[CONF_PLATFORM] diff --git a/homeassistant/components/telegram_bot/config_flow.py b/homeassistant/components/telegram_bot/config_flow.py index 5586b098757..63435a494f4 100644 --- a/homeassistant/components/telegram_bot/config_flow.py +++ b/homeassistant/components/telegram_bot/config_flow.py @@ -135,7 +135,7 @@ OPTIONS_SCHEMA: vol.Schema = vol.Schema( class OptionsFlowHandler(OptionsFlow): - """Options flow for webhooks.""" + """Options flow.""" async def async_step_init( self, user_input: dict[str, Any] | None = None