Fix Telegram bots using plain text parser failing to load on restart (#148050)

This commit is contained in:
hanwg 2025-07-04 22:32:46 +08:00 committed by GitHub
parent 04bd1967a7
commit cc2aca2c2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 7 deletions

View File

@ -374,9 +374,7 @@ class TelegramNotificationService:
} }
if data is not None: if data is not None:
if ATTR_PARSER in data: if ATTR_PARSER in data:
params[ATTR_PARSER] = self._parsers.get( params[ATTR_PARSER] = data[ATTR_PARSER]
data[ATTR_PARSER], self.parse_mode
)
if ATTR_TIMEOUT in data: if ATTR_TIMEOUT in data:
params[ATTR_TIMEOUT] = data[ATTR_TIMEOUT] params[ATTR_TIMEOUT] = data[ATTR_TIMEOUT]
if ATTR_DISABLE_NOTIF in data: if ATTR_DISABLE_NOTIF in data:
@ -408,6 +406,8 @@ class TelegramNotificationService:
params[ATTR_REPLYMARKUP] = InlineKeyboardMarkup( params[ATTR_REPLYMARKUP] = InlineKeyboardMarkup(
[_make_row_inline_keyboard(row) for row in keys] [_make_row_inline_keyboard(row) for row in keys]
) )
if params[ATTR_PARSER] == PARSER_PLAIN_TEXT:
params[ATTR_PARSER] = None
return params return params
async def _send_msg( async def _send_msg(

View File

@ -159,8 +159,6 @@ class OptionsFlowHandler(OptionsFlow):
"""Manage the options.""" """Manage the options."""
if user_input is not None: 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_create_entry(data=user_input)
return self.async_show_form( return self.async_show_form(

View File

@ -109,6 +109,7 @@ send_photo:
- "markdown" - "markdown"
- "markdownv2" - "markdownv2"
- "plain_text" - "plain_text"
translation_key: "parse_mode"
disable_notification: disable_notification:
selector: selector:
boolean: boolean:
@ -261,6 +262,7 @@ send_animation:
- "markdown" - "markdown"
- "markdownv2" - "markdownv2"
- "plain_text" - "plain_text"
translation_key: "parse_mode"
disable_notification: disable_notification:
selector: selector:
boolean: boolean:
@ -341,6 +343,7 @@ send_video:
- "markdown" - "markdown"
- "markdownv2" - "markdownv2"
- "plain_text" - "plain_text"
translation_key: "parse_mode"
disable_notification: disable_notification:
selector: selector:
boolean: boolean:
@ -493,6 +496,7 @@ send_document:
- "markdown" - "markdown"
- "markdownv2" - "markdownv2"
- "plain_text" - "plain_text"
translation_key: "parse_mode"
disable_notification: disable_notification:
selector: selector:
boolean: boolean:
@ -670,6 +674,7 @@ edit_message:
- "markdown" - "markdown"
- "markdownv2" - "markdownv2"
- "plain_text" - "plain_text"
translation_key: "parse_mode"
disable_web_page_preview: disable_web_page_preview:
selector: selector:
boolean: boolean:

View File

@ -63,7 +63,7 @@ async def test_options_flow(
await hass.async_block_till_done() await hass.async_block_till_done()
assert result["type"] == FlowResultType.CREATE_ENTRY assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"][ATTR_PARSER] is None assert result["data"][ATTR_PARSER] == PARSER_PLAIN_TEXT
async def test_reconfigure_flow_broadcast( async def test_reconfigure_flow_broadcast(

View File

@ -50,6 +50,7 @@ from homeassistant.components.telegram_bot.const import (
ATTR_VERIFY_SSL, ATTR_VERIFY_SSL,
CONF_CONFIG_ENTRY_ID, CONF_CONFIG_ENTRY_ID,
DOMAIN, DOMAIN,
PARSER_PLAIN_TEXT,
PLATFORM_BROADCAST, PLATFORM_BROADCAST,
SECTION_ADVANCED_SETTINGS, SECTION_ADVANCED_SETTINGS,
SERVICE_ANSWER_CALLBACK_QUERY, SERVICE_ANSWER_CALLBACK_QUERY,
@ -183,6 +184,7 @@ async def test_send_message(
( (
{ {
ATTR_MESSAGE: "test_message", ATTR_MESSAGE: "test_message",
ATTR_PARSER: PARSER_PLAIN_TEXT,
ATTR_KEYBOARD_INLINE: "command1:/cmd1,/cmd2,mock_link:https://mock_link", ATTR_KEYBOARD_INLINE: "command1:/cmd1,/cmd2,mock_link:https://mock_link",
}, },
InlineKeyboardMarkup( InlineKeyboardMarkup(
@ -199,6 +201,7 @@ async def test_send_message(
( (
{ {
ATTR_MESSAGE: "test_message", ATTR_MESSAGE: "test_message",
ATTR_PARSER: PARSER_PLAIN_TEXT,
ATTR_KEYBOARD_INLINE: [ ATTR_KEYBOARD_INLINE: [
[["command1", "/cmd1"]], [["command1", "/cmd1"]],
[["mock_link", "https://mock_link"]], [["mock_link", "https://mock_link"]],
@ -250,7 +253,7 @@ async def test_send_message_with_inline_keyboard(
mock_send_message.assert_called_once_with( mock_send_message.assert_called_once_with(
12345678, 12345678,
"test_message", "test_message",
parse_mode=ParseMode.MARKDOWN, parse_mode=None,
disable_web_page_preview=None, disable_web_page_preview=None,
disable_notification=False, disable_notification=False,
reply_to_message_id=None, reply_to_message_id=None,