Handle error in setup_entry for Telegram Bot (#146242)

* handle error in setup_entry

* Update homeassistant/components/telegram_bot/__init__.py

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>

---------

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
This commit is contained in:
hanwg 2025-06-06 22:00:48 +08:00 committed by GitHub
parent c4be3c4de2
commit d907e4c10b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -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]

View File

@ -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