From 30c2bb4ae4d850dae931a5f7e1525cf19e3be5d8 Mon Sep 17 00:00:00 2001 From: hanwg Date: Sat, 10 May 2025 13:20:47 +0000 Subject: [PATCH] added chat id in config entry title and added config flow tests --- .../components/telegram/config_flow.py | 2 +- homeassistant/components/telegram/notify.py | 2 +- .../components/telegram/strings.json | 2 +- tests/components/telegram/test_config_flow.py | 36 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tests/components/telegram/test_config_flow.py diff --git a/homeassistant/components/telegram/config_flow.py b/homeassistant/components/telegram/config_flow.py index 3db5c26a9ab..f112a066fc7 100644 --- a/homeassistant/components/telegram/config_flow.py +++ b/homeassistant/components/telegram/config_flow.py @@ -31,7 +31,7 @@ class TelgramConfigFlow(ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured() return self.async_create_entry( - title=user_input[CONF_NAME], + title=f"{user_input[CONF_NAME]} ({user_input[CONF_CHAT_ID]})", data={ CONF_NAME: user_input[CONF_NAME], CONF_CHAT_ID: user_input[CONF_CHAT_ID], diff --git a/homeassistant/components/telegram/notify.py b/homeassistant/components/telegram/notify.py index 28d298af12a..fa274fa7865 100644 --- a/homeassistant/components/telegram/notify.py +++ b/homeassistant/components/telegram/notify.py @@ -28,7 +28,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.reload import setup_reload_service from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import DOMAIN, PLATFORMS +from .const import DOMAIN, PLATFORMS _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/telegram/strings.json b/homeassistant/components/telegram/strings.json index b3c8d98d72a..d21778703ef 100644 --- a/homeassistant/components/telegram/strings.json +++ b/homeassistant/components/telegram/strings.json @@ -13,7 +13,7 @@ "chat_id": "Chat ID" }, "data_description": { - "name": "The name of the notifier.", + "name": "The name of the notifier. Must be unique.", "chat_id": "The Telegram chat ID." }, "description": "Please enter the notifier information", diff --git a/tests/components/telegram/test_config_flow.py b/tests/components/telegram/test_config_flow.py new file mode 100644 index 00000000000..0963b13d5c9 --- /dev/null +++ b/tests/components/telegram/test_config_flow.py @@ -0,0 +1,36 @@ +"""Test the Telegram config flow.""" + +from unittest.mock import patch + +from homeassistant.components import notify +from homeassistant.components.telegram.const import DOMAIN +from homeassistant.config_entries import SOURCE_USER +from homeassistant.core import HomeAssistant +from homeassistant.data_entry_flow import FlowResultType +from homeassistant.setup import async_setup_component + + +async def test_async_step_user(hass: HomeAssistant) -> None: + """Test config flow.""" + + with patch("homeassistant.components.telegram_bot.async_setup", return_value=True): + assert await async_setup_component( + hass, + notify.DOMAIN, + { + notify.DOMAIN: [ + { + "name": DOMAIN, + "platform": DOMAIN, + "chat_id": 1, + }, + ] + }, + ) + await hass.async_block_till_done() + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] == FlowResultType.FORM