mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
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:
parent
c4be3c4de2
commit
d907e4c10b
@ -8,7 +8,7 @@ from types import ModuleType
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from telegram import Bot
|
from telegram import Bot
|
||||||
from telegram.error import InvalidToken
|
from telegram.error import InvalidToken, TelegramError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT
|
from homeassistant.config_entries import SOURCE_IMPORT
|
||||||
@ -26,7 +26,11 @@ from homeassistant.core import (
|
|||||||
ServiceResponse,
|
ServiceResponse,
|
||||||
SupportsResponse,
|
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 import config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
@ -418,6 +422,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: TelegramBotConfigEntry)
|
|||||||
await bot.get_me()
|
await bot.get_me()
|
||||||
except InvalidToken as err:
|
except InvalidToken as err:
|
||||||
raise ConfigEntryAuthFailed("Invalid API token for Telegram Bot.") from 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]
|
p_type: str = entry.data[CONF_PLATFORM]
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ OPTIONS_SCHEMA: vol.Schema = vol.Schema(
|
|||||||
|
|
||||||
|
|
||||||
class OptionsFlowHandler(OptionsFlow):
|
class OptionsFlowHandler(OptionsFlow):
|
||||||
"""Options flow for webhooks."""
|
"""Options flow."""
|
||||||
|
|
||||||
async def async_step_init(
|
async def async_step_init(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user