mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 18:58:04 +02:00
added chat id in config entry title and added config flow tests
This commit is contained in:
@ -31,7 +31,7 @@ class TelgramConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_NAME],
|
title=f"{user_input[CONF_NAME]} ({user_input[CONF_CHAT_ID]})",
|
||||||
data={
|
data={
|
||||||
CONF_NAME: user_input[CONF_NAME],
|
CONF_NAME: user_input[CONF_NAME],
|
||||||
CONF_CHAT_ID: user_input[CONF_CHAT_ID],
|
CONF_CHAT_ID: user_input[CONF_CHAT_ID],
|
||||||
|
@ -28,7 +28,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.reload import setup_reload_service
|
from homeassistant.helpers.reload import setup_reload_service
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import DOMAIN, PLATFORMS
|
from .const import DOMAIN, PLATFORMS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"chat_id": "Chat ID"
|
"chat_id": "Chat ID"
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
"name": "The name of the notifier.",
|
"name": "The name of the notifier. Must be unique.",
|
||||||
"chat_id": "The Telegram chat ID."
|
"chat_id": "The Telegram chat ID."
|
||||||
},
|
},
|
||||||
"description": "Please enter the notifier information",
|
"description": "Please enter the notifier information",
|
||||||
|
36
tests/components/telegram/test_config_flow.py
Normal file
36
tests/components/telegram/test_config_flow.py
Normal 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
|
Reference in New Issue
Block a user