diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index e757830811f..2ef42e7d958 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -913,6 +913,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: TelegramBotConfigEntry) async def update_listener(hass: HomeAssistant, entry: TelegramBotConfigEntry) -> None: """Handle config changes.""" entry.runtime_data.parse_mode = entry.options[ATTR_PARSER] + if entry.runtime_data.old_config_data != entry.data: + # Reload if config data has changed + hass.config_entries.async_schedule_reload(entry.entry_id) # reload entities await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/telegram_bot/bot.py b/homeassistant/components/telegram_bot/bot.py index fd45e4c219d..1763ba617ff 100644 --- a/homeassistant/components/telegram_bot/bot.py +++ b/homeassistant/components/telegram_bot/bot.py @@ -302,6 +302,7 @@ class TelegramNotificationService: """Initialize the service.""" self.app = app self.config = config + self.old_config_data = config.data.copy() self._parsers: dict[str, str | None] = { PARSER_HTML: ParseMode.HTML, PARSER_MD: ParseMode.MARKDOWN, diff --git a/homeassistant/components/telegram_bot/config_flow.py b/homeassistant/components/telegram_bot/config_flow.py index c2d6ed368ed..596b2a65861 100644 --- a/homeassistant/components/telegram_bot/config_flow.py +++ b/homeassistant/components/telegram_bot/config_flow.py @@ -369,7 +369,7 @@ class TelegramBotConfigFlow(ConfigFlow, domain=DOMAIN): if self.source == SOURCE_RECONFIGURE: user_input.update(self._step_user_data) - return self.async_update_reload_and_abort( + return self.async_update_and_abort( self._get_reconfigure_entry(), title=self._bot_name, data_updates=user_input, @@ -534,7 +534,7 @@ class TelegramBotConfigFlow(ConfigFlow, domain=DOMAIN): if user_input[CONF_PLATFORM] != PLATFORM_WEBHOOKS: await self._shutdown_bot() - return self.async_update_reload_and_abort( + return self.async_update_and_abort( self._get_reconfigure_entry(), title=bot_name, data_updates=user_input ) @@ -579,7 +579,7 @@ class TelegramBotConfigFlow(ConfigFlow, domain=DOMAIN): description_placeholders=description_placeholders, ) - return self.async_update_reload_and_abort( + return self.async_update_and_abort( self._get_reauth_entry(), title=bot_name, data_updates=updated_data ) diff --git a/tests/components/telegram_bot/test_config_flow.py b/tests/components/telegram_bot/test_config_flow.py index 5db2e92edbf..df398efca00 100644 --- a/tests/components/telegram_bot/test_config_flow.py +++ b/tests/components/telegram_bot/test_config_flow.py @@ -75,11 +75,14 @@ async def test_options_flow( async def test_reconfigure_flow_broadcast( hass: HomeAssistant, - mock_webhooks_config_entry: MockConfigEntry, + mock_register_webhook: None, mock_external_calls: None, + mock_webhooks_config_entry: MockConfigEntry, ) -> None: """Test reconfigure flow for broadcast bot.""" mock_webhooks_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(mock_webhooks_config_entry.entry_id) + await hass.async_block_till_done() result = await mock_webhooks_config_entry.start_reconfigure_flow(hass) assert result["step_id"] == "reconfigure"