1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Fix event entity state update for Telegram bot (#155510)

This commit is contained in:
hanwg
2025-11-03 08:04:57 +08:00
committed by GitHub
parent 1badfe3aff
commit 6137a643d8
4 changed files with 16 additions and 5 deletions
+3 -3
View File
@@ -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:
@@ -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,
)
)
@@ -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}"
@@ -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"))