Skip to content

Commit 6137a64

Browse files
authored
Fix event entity state update for Telegram bot (#155510)
1 parent 1badfe3 commit 6137a64

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

homeassistant/components/telegram_bot/bot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
SERVICE_SEND_STICKER,
109109
SERVICE_SEND_VIDEO,
110110
SERVICE_SEND_VOICE,
111-
SIGNAL_UPDATE_EVENT,
112111
)
112+
from .helpers import signal
113113

114114
_FILE_TYPES = ("animation", "document", "photo", "sticker", "video", "voice")
115115
_LOGGER = logging.getLogger(__name__)
@@ -169,7 +169,7 @@ async def handle_update(self, update: Update, context: CallbackContext) -> bool:
169169

170170
_LOGGER.debug("Firing event %s: %s", event_type, event_data)
171171
self.hass.bus.async_fire(event_type, event_data, context=event_context)
172-
async_dispatcher_send(self.hass, SIGNAL_UPDATE_EVENT, event_type, event_data)
172+
async_dispatcher_send(self.hass, signal(self._bot), event_type, event_data)
173173
return True
174174

175175
@staticmethod
@@ -551,7 +551,7 @@ async def _send_msg(
551551
EVENT_TELEGRAM_SENT, event_data, context=context
552552
)
553553
async_dispatcher_send(
554-
self.hass, SIGNAL_UPDATE_EVENT, EVENT_TELEGRAM_SENT, event_data
554+
self.hass, signal(self.bot), EVENT_TELEGRAM_SENT, event_data
555555
)
556556
except TelegramError as exc:
557557
if not suppress_error:

homeassistant/components/telegram_bot/event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
EVENT_TELEGRAM_COMMAND,
1515
EVENT_TELEGRAM_SENT,
1616
EVENT_TELEGRAM_TEXT,
17-
SIGNAL_UPDATE_EVENT,
1817
)
1918
from .entity import TelegramBotEntity
19+
from .helpers import signal
2020

2121

2222
async def async_setup_entry(
@@ -55,7 +55,7 @@ async def async_added_to_hass(self) -> None:
5555
self.async_on_remove(
5656
async_dispatcher_connect(
5757
self.hass,
58-
SIGNAL_UPDATE_EVENT,
58+
signal(self.config_entry.runtime_data.bot),
5959
self._async_handle_event,
6060
)
6161
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Helper functions for Telegram bot integration."""
2+
3+
from telegram import Bot
4+
5+
from .const import SIGNAL_UPDATE_EVENT
6+
7+
8+
def signal(bot: Bot) -> str:
9+
"""Define signal name."""
10+
return f"{SIGNAL_UPDATE_EVENT}_{bot.id}"

tests/components/telegram_bot/test_event.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ async def test_send_message(
3737
await hass.async_block_till_done()
3838

3939
state = hass.states.get("event.mock_title_update_event")
40+
assert state is not None
4041
assert state.attributes == snapshot(exclude=props("config_entry_id"))

0 commit comments

Comments
 (0)