mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Fix Telegram bot leave_chat service action (#146139)
* bug fix for leave chat * update strings
This commit is contained in:
parent
db8a6f8583
commit
627831dfaf
@ -374,6 +374,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
)
|
)
|
||||||
elif msgtype == SERVICE_DELETE_MESSAGE:
|
elif msgtype == SERVICE_DELETE_MESSAGE:
|
||||||
await notify_service.delete_message(context=service.context, **kwargs)
|
await notify_service.delete_message(context=service.context, **kwargs)
|
||||||
|
elif msgtype == SERVICE_LEAVE_CHAT:
|
||||||
|
messages = await notify_service.leave_chat(
|
||||||
|
context=service.context, **kwargs
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await notify_service.edit_message(
|
await notify_service.edit_message(
|
||||||
msgtype, context=service.context, **kwargs
|
msgtype, context=service.context, **kwargs
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
},
|
},
|
||||||
"delete_message": {
|
"delete_message": {
|
||||||
"service": "mdi:delete"
|
"service": "mdi:delete"
|
||||||
|
},
|
||||||
|
"leave_chat": {
|
||||||
|
"service": "mdi:exit-run"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -774,3 +774,15 @@ delete_message:
|
|||||||
example: 12345
|
example: 12345
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
|
|
||||||
|
leave_chat:
|
||||||
|
fields:
|
||||||
|
config_entry_id:
|
||||||
|
selector:
|
||||||
|
config_entry:
|
||||||
|
integration: telegram_bot
|
||||||
|
chat_id:
|
||||||
|
required: true
|
||||||
|
example: 12345
|
||||||
|
selector:
|
||||||
|
text:
|
||||||
|
@ -842,6 +842,20 @@
|
|||||||
"description": "ID of the chat where to delete the message."
|
"description": "ID of the chat where to delete the message."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"leave_chat": {
|
||||||
|
"name": "Leave chat",
|
||||||
|
"description": "Removes the bot from the chat.",
|
||||||
|
"fields": {
|
||||||
|
"config_entry_id": {
|
||||||
|
"name": "[%key:component::telegram_bot::services::send_message::fields::config_entry_id::name%]",
|
||||||
|
"description": "The config entry representing the Telegram bot to leave the chat."
|
||||||
|
},
|
||||||
|
"chat_id": {
|
||||||
|
"name": "[%key:component::telegram_bot::services::edit_message::fields::chat_id::name%]",
|
||||||
|
"description": "Chat ID of the group from which the bot should be removed."
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
|
@ -39,6 +39,7 @@ from homeassistant.components.telegram_bot import (
|
|||||||
SERVICE_EDIT_CAPTION,
|
SERVICE_EDIT_CAPTION,
|
||||||
SERVICE_EDIT_MESSAGE,
|
SERVICE_EDIT_MESSAGE,
|
||||||
SERVICE_EDIT_REPLYMARKUP,
|
SERVICE_EDIT_REPLYMARKUP,
|
||||||
|
SERVICE_LEAVE_CHAT,
|
||||||
SERVICE_SEND_ANIMATION,
|
SERVICE_SEND_ANIMATION,
|
||||||
SERVICE_SEND_DOCUMENT,
|
SERVICE_SEND_DOCUMENT,
|
||||||
SERVICE_SEND_LOCATION,
|
SERVICE_SEND_LOCATION,
|
||||||
@ -754,3 +755,30 @@ async def test_answer_callback_query(
|
|||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
mock.assert_called_once()
|
mock.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_leave_chat(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_broadcast_config_entry: MockConfigEntry,
|
||||||
|
mock_external_calls: None,
|
||||||
|
) -> None:
|
||||||
|
"""Test answer callback query."""
|
||||||
|
mock_broadcast_config_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(mock_broadcast_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.telegram_bot.bot.TelegramNotificationService.leave_chat",
|
||||||
|
AsyncMock(return_value=True),
|
||||||
|
) as mock:
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_LEAVE_CHAT,
|
||||||
|
{
|
||||||
|
ATTR_CHAT_ID: 12345,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
mock.assert_called_once()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user