mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Bug fix for Telegram bot integration: Handle plain text parse_mode (#146535)
This commit is contained in:
parent
b02c0419b4
commit
0af41d9cb1
@ -233,13 +233,13 @@ class TelegramNotificationService:
|
||||
"""Initialize the service."""
|
||||
self.app = app
|
||||
self.config = config
|
||||
self._parsers = {
|
||||
self._parsers: dict[str, str | None] = {
|
||||
PARSER_HTML: ParseMode.HTML,
|
||||
PARSER_MD: ParseMode.MARKDOWN,
|
||||
PARSER_MD2: ParseMode.MARKDOWN_V2,
|
||||
PARSER_PLAIN_TEXT: None,
|
||||
}
|
||||
self.parse_mode = self._parsers.get(parser)
|
||||
self.parse_mode = self._parsers[parser]
|
||||
self.bot = bot
|
||||
self.hass = hass
|
||||
self._last_message_id: dict[int, int] = {}
|
||||
|
@ -54,6 +54,7 @@ from .const import (
|
||||
PARSER_HTML,
|
||||
PARSER_MD,
|
||||
PARSER_MD2,
|
||||
PARSER_PLAIN_TEXT,
|
||||
PLATFORM_BROADCAST,
|
||||
PLATFORM_POLLING,
|
||||
PLATFORM_WEBHOOKS,
|
||||
@ -126,8 +127,8 @@ OPTIONS_SCHEMA: vol.Schema = vol.Schema(
|
||||
ATTR_PARSER,
|
||||
): SelectSelector(
|
||||
SelectSelectorConfig(
|
||||
options=[PARSER_MD, PARSER_MD2, PARSER_HTML],
|
||||
translation_key="parsers",
|
||||
options=[PARSER_MD, PARSER_MD2, PARSER_HTML, PARSER_PLAIN_TEXT],
|
||||
translation_key="parse_mode",
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -143,6 +144,8 @@ class OptionsFlowHandler(OptionsFlow):
|
||||
"""Manage the options."""
|
||||
|
||||
if user_input is not None:
|
||||
if user_input[ATTR_PARSER] == PARSER_PLAIN_TEXT:
|
||||
user_input[ATTR_PARSER] = None
|
||||
return self.async_create_entry(data=user_input)
|
||||
|
||||
return self.async_show_form(
|
||||
|
@ -27,6 +27,7 @@ send_message:
|
||||
- "markdown"
|
||||
- "markdownv2"
|
||||
- "plain_text"
|
||||
translation_key: "parse_mode"
|
||||
disable_notification:
|
||||
selector:
|
||||
boolean:
|
||||
|
@ -106,11 +106,12 @@
|
||||
"webhooks": "Webhooks"
|
||||
}
|
||||
},
|
||||
"parsers": {
|
||||
"parse_mode": {
|
||||
"options": {
|
||||
"markdown": "Markdown (Legacy)",
|
||||
"markdownv2": "MarkdownV2",
|
||||
"html": "HTML"
|
||||
"html": "HTML",
|
||||
"plain_text": "Plain text"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -19,8 +19,8 @@ from homeassistant.components.telegram_bot.const import (
|
||||
ERROR_MESSAGE,
|
||||
ISSUE_DEPRECATED_YAML,
|
||||
ISSUE_DEPRECATED_YAML_IMPORT_ISSUE_ERROR,
|
||||
PARSER_HTML,
|
||||
PARSER_MD,
|
||||
PARSER_PLAIN_TEXT,
|
||||
PLATFORM_BROADCAST,
|
||||
PLATFORM_WEBHOOKS,
|
||||
SUBENTRY_TYPE_ALLOWED_CHAT_IDS,
|
||||
@ -56,13 +56,13 @@ async def test_options_flow(
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
ATTR_PARSER: PARSER_HTML,
|
||||
ATTR_PARSER: PARSER_PLAIN_TEXT,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["data"][ATTR_PARSER] == PARSER_HTML
|
||||
assert result["data"][ATTR_PARSER] is None
|
||||
|
||||
|
||||
async def test_reconfigure_flow_broadcast(
|
||||
|
Loading…
x
Reference in New Issue
Block a user