diff --git a/homeassistant/components/telegram_bot/bot.py b/homeassistant/components/telegram_bot/bot.py index a0f7cc841a2..d1ab9e62b24 100644 --- a/homeassistant/components/telegram_bot/bot.py +++ b/homeassistant/components/telegram_bot/bot.py @@ -108,8 +108,8 @@ from .const import ( SERVICE_SEND_STICKER, SERVICE_SEND_VIDEO, SERVICE_SEND_VOICE, - SIGNAL_UPDATE_EVENT, ) +from .helpers import signal _FILE_TYPES = ("animation", "document", "photo", "sticker", "video", "voice") _LOGGER = logging.getLogger(__name__) @@ -169,7 +169,7 @@ class BaseTelegramBot: _LOGGER.debug("Firing event %s: %s", event_type, event_data) self.hass.bus.async_fire(event_type, event_data, context=event_context) - async_dispatcher_send(self.hass, SIGNAL_UPDATE_EVENT, event_type, event_data) + async_dispatcher_send(self.hass, signal(self._bot), event_type, event_data) return True @staticmethod @@ -551,7 +551,7 @@ class TelegramNotificationService: EVENT_TELEGRAM_SENT, event_data, context=context ) async_dispatcher_send( - self.hass, SIGNAL_UPDATE_EVENT, EVENT_TELEGRAM_SENT, event_data + self.hass, signal(self.bot), EVENT_TELEGRAM_SENT, event_data ) except TelegramError as exc: if not suppress_error: diff --git a/homeassistant/components/telegram_bot/event.py b/homeassistant/components/telegram_bot/event.py index db45c4c135a..04e8ecb8246 100644 --- a/homeassistant/components/telegram_bot/event.py +++ b/homeassistant/components/telegram_bot/event.py @@ -14,9 +14,9 @@ from .const import ( EVENT_TELEGRAM_COMMAND, EVENT_TELEGRAM_SENT, EVENT_TELEGRAM_TEXT, - SIGNAL_UPDATE_EVENT, ) from .entity import TelegramBotEntity +from .helpers import signal async def async_setup_entry( @@ -55,7 +55,7 @@ class TelegramBotEventEntity(TelegramBotEntity, EventEntity): self.async_on_remove( async_dispatcher_connect( self.hass, - SIGNAL_UPDATE_EVENT, + signal(self.config_entry.runtime_data.bot), self._async_handle_event, ) ) diff --git a/homeassistant/components/telegram_bot/helpers.py b/homeassistant/components/telegram_bot/helpers.py new file mode 100644 index 00000000000..4b4acbb37fa --- /dev/null +++ b/homeassistant/components/telegram_bot/helpers.py @@ -0,0 +1,10 @@ +"""Helper functions for Telegram bot integration.""" + +from telegram import Bot + +from .const import SIGNAL_UPDATE_EVENT + + +def signal(bot: Bot) -> str: + """Define signal name.""" + return f"{SIGNAL_UPDATE_EVENT}_{bot.id}" diff --git a/tests/components/telegram_bot/test_event.py b/tests/components/telegram_bot/test_event.py index e1e1cff68eb..70d3c6960dc 100644 --- a/tests/components/telegram_bot/test_event.py +++ b/tests/components/telegram_bot/test_event.py @@ -37,4 +37,5 @@ async def test_send_message( await hass.async_block_till_done() state = hass.states.get("event.mock_title_update_event") + assert state is not None assert state.attributes == snapshot(exclude=props("config_entry_id"))