mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Fix Telegram bots using plain text parser failing to load on restart (#148050)
This commit is contained in:
parent
04bd1967a7
commit
cc2aca2c2c
@ -374,9 +374,7 @@ class TelegramNotificationService:
|
||||
}
|
||||
if data is not None:
|
||||
if ATTR_PARSER in data:
|
||||
params[ATTR_PARSER] = self._parsers.get(
|
||||
data[ATTR_PARSER], self.parse_mode
|
||||
)
|
||||
params[ATTR_PARSER] = data[ATTR_PARSER]
|
||||
if ATTR_TIMEOUT in data:
|
||||
params[ATTR_TIMEOUT] = data[ATTR_TIMEOUT]
|
||||
if ATTR_DISABLE_NOTIF in data:
|
||||
@ -408,6 +406,8 @@ class TelegramNotificationService:
|
||||
params[ATTR_REPLYMARKUP] = InlineKeyboardMarkup(
|
||||
[_make_row_inline_keyboard(row) for row in keys]
|
||||
)
|
||||
if params[ATTR_PARSER] == PARSER_PLAIN_TEXT:
|
||||
params[ATTR_PARSER] = None
|
||||
return params
|
||||
|
||||
async def _send_msg(
|
||||
|
@ -159,8 +159,6 @@ 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(
|
||||
|
@ -109,6 +109,7 @@ send_photo:
|
||||
- "markdown"
|
||||
- "markdownv2"
|
||||
- "plain_text"
|
||||
translation_key: "parse_mode"
|
||||
disable_notification:
|
||||
selector:
|
||||
boolean:
|
||||
@ -261,6 +262,7 @@ send_animation:
|
||||
- "markdown"
|
||||
- "markdownv2"
|
||||
- "plain_text"
|
||||
translation_key: "parse_mode"
|
||||
disable_notification:
|
||||
selector:
|
||||
boolean:
|
||||
@ -341,6 +343,7 @@ send_video:
|
||||
- "markdown"
|
||||
- "markdownv2"
|
||||
- "plain_text"
|
||||
translation_key: "parse_mode"
|
||||
disable_notification:
|
||||
selector:
|
||||
boolean:
|
||||
@ -493,6 +496,7 @@ send_document:
|
||||
- "markdown"
|
||||
- "markdownv2"
|
||||
- "plain_text"
|
||||
translation_key: "parse_mode"
|
||||
disable_notification:
|
||||
selector:
|
||||
boolean:
|
||||
@ -670,6 +674,7 @@ edit_message:
|
||||
- "markdown"
|
||||
- "markdownv2"
|
||||
- "plain_text"
|
||||
translation_key: "parse_mode"
|
||||
disable_web_page_preview:
|
||||
selector:
|
||||
boolean:
|
||||
|
@ -63,7 +63,7 @@ async def test_options_flow(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
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(
|
||||
|
@ -50,6 +50,7 @@ from homeassistant.components.telegram_bot.const import (
|
||||
ATTR_VERIFY_SSL,
|
||||
CONF_CONFIG_ENTRY_ID,
|
||||
DOMAIN,
|
||||
PARSER_PLAIN_TEXT,
|
||||
PLATFORM_BROADCAST,
|
||||
SECTION_ADVANCED_SETTINGS,
|
||||
SERVICE_ANSWER_CALLBACK_QUERY,
|
||||
@ -183,6 +184,7 @@ async def test_send_message(
|
||||
(
|
||||
{
|
||||
ATTR_MESSAGE: "test_message",
|
||||
ATTR_PARSER: PARSER_PLAIN_TEXT,
|
||||
ATTR_KEYBOARD_INLINE: "command1:/cmd1,/cmd2,mock_link:https://mock_link",
|
||||
},
|
||||
InlineKeyboardMarkup(
|
||||
@ -199,6 +201,7 @@ async def test_send_message(
|
||||
(
|
||||
{
|
||||
ATTR_MESSAGE: "test_message",
|
||||
ATTR_PARSER: PARSER_PLAIN_TEXT,
|
||||
ATTR_KEYBOARD_INLINE: [
|
||||
[["command1", "/cmd1"]],
|
||||
[["mock_link", "https://mock_link"]],
|
||||
@ -250,7 +253,7 @@ async def test_send_message_with_inline_keyboard(
|
||||
mock_send_message.assert_called_once_with(
|
||||
12345678,
|
||||
"test_message",
|
||||
parse_mode=ParseMode.MARKDOWN,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None,
|
||||
disable_notification=False,
|
||||
reply_to_message_id=None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user