added chat id in config entry title and added config flow tests

This commit is contained in:
hanwg
2025-05-10 13:20:47 +00:00
parent 0f7260f4a6
commit 30c2bb4ae4
4 changed files with 39 additions and 3 deletions

View File

@ -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],

View File

@ -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__)

View File

@ -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",

View File

@ -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