Fix telegram broadcast (#69452)
This commit is contained in:
parent
bc194cd209
commit
c765e11f55
4 changed files with 31 additions and 22 deletions
|
@ -1,17 +1,6 @@
|
|||
"""Support for Telegram bot to send messages only."""
|
||||
import logging
|
||||
|
||||
from . import initialize_bot
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config):
|
||||
async def async_setup_platform(hass, bot, config):
|
||||
"""Set up the Telegram broadcast platform."""
|
||||
bot = initialize_bot(config)
|
||||
|
||||
bot_config = await hass.async_add_executor_job(bot.getMe)
|
||||
_LOGGER.debug(
|
||||
"Telegram broadcast platform setup with bot %s", bot_config["username"]
|
||||
)
|
||||
return True
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from telegram.ext.dispatcher import Dispatcher
|
||||
|
||||
from homeassistant.components.telegram_bot import (
|
||||
CONF_ALLOWED_CHAT_IDS,
|
||||
|
@ -176,12 +175,3 @@ async def polling_platform(hass, config_polling):
|
|||
config_polling,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_dispatcher():
|
||||
"""Clear the singleton that telegram.ext.dispatcher.Dispatcher sets on itself."""
|
||||
yield
|
||||
Dispatcher._set_singleton(None)
|
||||
# This is how python-telegram-bot resets the dispatcher in their test suite
|
||||
Dispatcher._Dispatcher__singleton_semaphore.release()
|
||||
|
|
20
tests/components/telegram_bot/test_broadcast.py
Normal file
20
tests/components/telegram_bot/test_broadcast.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
"""Test Telegram broadcast."""
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
async def test_setup(hass):
|
||||
"""Test setting up Telegram broadcast."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"telegram_bot",
|
||||
{
|
||||
"telegram_bot": {
|
||||
"platform": "broadcast",
|
||||
"api_key": "1234567890:ABC",
|
||||
"allowed_chat_ids": [1],
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.services.has_service("telegram_bot", "send_message") is True
|
|
@ -1,4 +1,5 @@
|
|||
"""Tests for the telegram_bot component."""
|
||||
import pytest
|
||||
from telegram import Update
|
||||
from telegram.ext.dispatcher import Dispatcher
|
||||
|
||||
|
@ -8,6 +9,15 @@ from homeassistant.components.telegram_bot.webhooks import TELEGRAM_WEBHOOK_URL
|
|||
from tests.common import async_capture_events
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_dispatcher():
|
||||
"""Clear the singleton that telegram.ext.dispatcher.Dispatcher sets on itself."""
|
||||
yield
|
||||
Dispatcher._set_singleton(None)
|
||||
# This is how python-telegram-bot resets the dispatcher in their test suite
|
||||
Dispatcher._Dispatcher__singleton_semaphore.release()
|
||||
|
||||
|
||||
async def test_webhook_platform_init(hass, webhook_platform):
|
||||
"""Test initialization of the webhooks platform."""
|
||||
assert hass.services.has_service(DOMAIN, SERVICE_SEND_MESSAGE) is True
|
||||
|
|
Loading…
Add table
Reference in a new issue