mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Hide Telegram bot proxy URL behind section (#147613)
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
This commit is contained in:
parent
4df1f702bf
commit
26521f8cc0
@ -22,7 +22,7 @@ from homeassistant.config_entries import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_PLATFORM, CONF_URL
|
from homeassistant.const import CONF_API_KEY, CONF_PLATFORM, CONF_URL
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.data_entry_flow import AbortFlow
|
from homeassistant.data_entry_flow import AbortFlow, section
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||||
@ -58,6 +58,7 @@ from .const import (
|
|||||||
PLATFORM_BROADCAST,
|
PLATFORM_BROADCAST,
|
||||||
PLATFORM_POLLING,
|
PLATFORM_POLLING,
|
||||||
PLATFORM_WEBHOOKS,
|
PLATFORM_WEBHOOKS,
|
||||||
|
SECTION_ADVANCED_SETTINGS,
|
||||||
SUBENTRY_TYPE_ALLOWED_CHAT_IDS,
|
SUBENTRY_TYPE_ALLOWED_CHAT_IDS,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -81,9 +82,16 @@ STEP_USER_DATA_SCHEMA: vol.Schema = vol.Schema(
|
|||||||
autocomplete="current-password",
|
autocomplete="current-password",
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
vol.Required(SECTION_ADVANCED_SETTINGS): section(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
vol.Optional(CONF_PROXY_URL): TextSelector(
|
vol.Optional(CONF_PROXY_URL): TextSelector(
|
||||||
config=TextSelectorConfig(type=TextSelectorType.URL)
|
config=TextSelectorConfig(type=TextSelectorType.URL)
|
||||||
),
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
{"collapsed": True},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
STEP_RECONFIGURE_USER_DATA_SCHEMA: vol.Schema = vol.Schema(
|
STEP_RECONFIGURE_USER_DATA_SCHEMA: vol.Schema = vol.Schema(
|
||||||
@ -98,9 +106,16 @@ STEP_RECONFIGURE_USER_DATA_SCHEMA: vol.Schema = vol.Schema(
|
|||||||
translation_key="platforms",
|
translation_key="platforms",
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
vol.Required(SECTION_ADVANCED_SETTINGS): section(
|
||||||
|
vol.Schema(
|
||||||
|
{
|
||||||
vol.Optional(CONF_PROXY_URL): TextSelector(
|
vol.Optional(CONF_PROXY_URL): TextSelector(
|
||||||
config=TextSelectorConfig(type=TextSelectorType.URL)
|
config=TextSelectorConfig(type=TextSelectorType.URL)
|
||||||
),
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
{"collapsed": True},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
STEP_REAUTH_DATA_SCHEMA: vol.Schema = vol.Schema(
|
STEP_REAUTH_DATA_SCHEMA: vol.Schema = vol.Schema(
|
||||||
@ -197,6 +212,9 @@ class TelgramBotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
import_data[CONF_TRUSTED_NETWORKS] = ",".join(
|
import_data[CONF_TRUSTED_NETWORKS] = ",".join(
|
||||||
import_data[CONF_TRUSTED_NETWORKS]
|
import_data[CONF_TRUSTED_NETWORKS]
|
||||||
)
|
)
|
||||||
|
import_data[SECTION_ADVANCED_SETTINGS] = {
|
||||||
|
CONF_PROXY_URL: import_data.get(CONF_PROXY_URL)
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
config_flow_result: ConfigFlowResult = await self.async_step_user(
|
config_flow_result: ConfigFlowResult = await self.async_step_user(
|
||||||
import_data
|
import_data
|
||||||
@ -332,7 +350,7 @@ class TelgramBotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
data={
|
data={
|
||||||
CONF_PLATFORM: user_input[CONF_PLATFORM],
|
CONF_PLATFORM: user_input[CONF_PLATFORM],
|
||||||
CONF_API_KEY: user_input[CONF_API_KEY],
|
CONF_API_KEY: user_input[CONF_API_KEY],
|
||||||
CONF_PROXY_URL: user_input.get(CONF_PROXY_URL),
|
CONF_PROXY_URL: user_input["advanced_settings"].get(CONF_PROXY_URL),
|
||||||
},
|
},
|
||||||
options={
|
options={
|
||||||
# this value may come from yaml import
|
# this value may come from yaml import
|
||||||
@ -444,7 +462,9 @@ class TelgramBotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
data={
|
data={
|
||||||
CONF_PLATFORM: self._step_user_data[CONF_PLATFORM],
|
CONF_PLATFORM: self._step_user_data[CONF_PLATFORM],
|
||||||
CONF_API_KEY: self._step_user_data[CONF_API_KEY],
|
CONF_API_KEY: self._step_user_data[CONF_API_KEY],
|
||||||
CONF_PROXY_URL: self._step_user_data.get(CONF_PROXY_URL),
|
CONF_PROXY_URL: self._step_user_data[SECTION_ADVANCED_SETTINGS].get(
|
||||||
|
CONF_PROXY_URL
|
||||||
|
),
|
||||||
CONF_URL: user_input.get(CONF_URL),
|
CONF_URL: user_input.get(CONF_URL),
|
||||||
CONF_TRUSTED_NETWORKS: user_input[CONF_TRUSTED_NETWORKS],
|
CONF_TRUSTED_NETWORKS: user_input[CONF_TRUSTED_NETWORKS],
|
||||||
},
|
},
|
||||||
@ -509,8 +529,18 @@ class TelgramBotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="reconfigure",
|
step_id="reconfigure",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
STEP_RECONFIGURE_USER_DATA_SCHEMA,
|
STEP_RECONFIGURE_USER_DATA_SCHEMA,
|
||||||
self._get_reconfigure_entry().data,
|
{
|
||||||
|
**self._get_reconfigure_entry().data,
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
|
CONF_PROXY_URL: self._get_reconfigure_entry().data.get(
|
||||||
|
CONF_PROXY_URL
|
||||||
),
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
user_input[CONF_PROXY_URL] = user_input[SECTION_ADVANCED_SETTINGS].get(
|
||||||
|
CONF_PROXY_URL
|
||||||
)
|
)
|
||||||
|
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
@ -527,7 +557,12 @@ class TelgramBotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="reconfigure",
|
step_id="reconfigure",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
STEP_RECONFIGURE_USER_DATA_SCHEMA,
|
STEP_RECONFIGURE_USER_DATA_SCHEMA,
|
||||||
user_input,
|
{
|
||||||
|
**user_input,
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
|
CONF_PROXY_URL: user_input.get(CONF_PROXY_URL),
|
||||||
|
},
|
||||||
|
},
|
||||||
),
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
description_placeholders=description_placeholders,
|
description_placeholders=description_placeholders,
|
||||||
|
@ -7,7 +7,7 @@ DOMAIN = "telegram_bot"
|
|||||||
PLATFORM_BROADCAST = "broadcast"
|
PLATFORM_BROADCAST = "broadcast"
|
||||||
PLATFORM_POLLING = "polling"
|
PLATFORM_POLLING = "polling"
|
||||||
PLATFORM_WEBHOOKS = "webhooks"
|
PLATFORM_WEBHOOKS = "webhooks"
|
||||||
|
SECTION_ADVANCED_SETTINGS = "advanced_settings"
|
||||||
SUBENTRY_TYPE_ALLOWED_CHAT_IDS = "allowed_chat_ids"
|
SUBENTRY_TYPE_ALLOWED_CHAT_IDS = "allowed_chat_ids"
|
||||||
|
|
||||||
CONF_BOT_COUNT = "bot_count"
|
CONF_BOT_COUNT = "bot_count"
|
||||||
|
@ -5,14 +5,23 @@
|
|||||||
"description": "To create a Telegram bot, follow these steps:\n\n1. Open Telegram and start a chat with [{botfather_username}]({botfather_url}).\n1. Send the command `/newbot`.\n1. Follow the instructions to create your bot and get your API token.",
|
"description": "To create a Telegram bot, follow these steps:\n\n1. Open Telegram and start a chat with [{botfather_username}]({botfather_url}).\n1. Send the command `/newbot`.\n1. Follow the instructions to create your bot and get your API token.",
|
||||||
"data": {
|
"data": {
|
||||||
"platform": "Platform",
|
"platform": "Platform",
|
||||||
"api_key": "[%key:common::config_flow::data::api_token%]",
|
"api_key": "[%key:common::config_flow::data::api_token%]"
|
||||||
"proxy_url": "Proxy URL"
|
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
"platform": "Telegram bot implementation",
|
"platform": "Telegram bot implementation",
|
||||||
"api_key": "The API token of your bot.",
|
"api_key": "The API token of your bot."
|
||||||
|
},
|
||||||
|
"sections": {
|
||||||
|
"advanced_settings": {
|
||||||
|
"name": "Advanced settings",
|
||||||
|
"data": {
|
||||||
|
"proxy_url": "Proxy URL"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
"proxy_url": "Proxy URL if working behind one, optionally including username and password.\n(socks5://username:password@proxy_ip:proxy_port)"
|
"proxy_url": "Proxy URL if working behind one, optionally including username and password.\n(socks5://username:password@proxy_ip:proxy_port)"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"webhooks": {
|
"webhooks": {
|
||||||
"title": "Webhooks network configuration",
|
"title": "Webhooks network configuration",
|
||||||
@ -29,12 +38,21 @@
|
|||||||
"title": "Telegram bot setup",
|
"title": "Telegram bot setup",
|
||||||
"description": "Reconfigure Telegram bot",
|
"description": "Reconfigure Telegram bot",
|
||||||
"data": {
|
"data": {
|
||||||
"platform": "[%key:component::telegram_bot::config::step::user::data::platform%]",
|
"platform": "[%key:component::telegram_bot::config::step::user::data::platform%]"
|
||||||
"proxy_url": "[%key:component::telegram_bot::config::step::user::data::proxy_url%]"
|
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
"platform": "[%key:component::telegram_bot::config::step::user::data_description::platform%]",
|
"platform": "[%key:component::telegram_bot::config::step::user::data_description::platform%]"
|
||||||
"proxy_url": "[%key:component::telegram_bot::config::step::user::data_description::proxy_url%]"
|
},
|
||||||
|
"sections": {
|
||||||
|
"advanced_settings": {
|
||||||
|
"name": "[%key:component::telegram_bot::config::step::user::sections::advanced_settings::name%]",
|
||||||
|
"data": {
|
||||||
|
"proxy_url": "[%key:component::telegram_bot::config::step::user::sections::advanced_settings::data::proxy_url%]"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"proxy_url": "[%key:component::telegram_bot::config::step::user::sections::advanced_settings::data_description::proxy_url%]"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"reauth_confirm": {
|
"reauth_confirm": {
|
||||||
|
@ -23,6 +23,7 @@ from homeassistant.components.telegram_bot.const import (
|
|||||||
PARSER_PLAIN_TEXT,
|
PARSER_PLAIN_TEXT,
|
||||||
PLATFORM_BROADCAST,
|
PLATFORM_BROADCAST,
|
||||||
PLATFORM_WEBHOOKS,
|
PLATFORM_WEBHOOKS,
|
||||||
|
SECTION_ADVANCED_SETTINGS,
|
||||||
SUBENTRY_TYPE_ALLOWED_CHAT_IDS,
|
SUBENTRY_TYPE_ALLOWED_CHAT_IDS,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, ConfigSubentry
|
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, ConfigSubentry
|
||||||
@ -89,8 +90,10 @@ async def test_reconfigure_flow_broadcast(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_PLATFORM: PLATFORM_BROADCAST,
|
CONF_PLATFORM: PLATFORM_BROADCAST,
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
CONF_PROXY_URL: "invalid",
|
CONF_PROXY_URL: "invalid",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -104,8 +107,10 @@ async def test_reconfigure_flow_broadcast(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_PLATFORM: PLATFORM_BROADCAST,
|
CONF_PLATFORM: PLATFORM_BROADCAST,
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
CONF_PROXY_URL: "https://test",
|
CONF_PROXY_URL: "https://test",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -131,8 +136,10 @@ async def test_reconfigure_flow_webhooks(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_PLATFORM: PLATFORM_WEBHOOKS,
|
CONF_PLATFORM: PLATFORM_WEBHOOKS,
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
CONF_PROXY_URL: "https://test",
|
CONF_PROXY_URL: "https://test",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -197,9 +204,7 @@ async def test_reconfigure_flow_webhooks(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_create_entry(
|
async def test_create_entry(hass: HomeAssistant) -> None:
|
||||||
hass: HomeAssistant,
|
|
||||||
) -> None:
|
|
||||||
"""Test user flow."""
|
"""Test user flow."""
|
||||||
|
|
||||||
# test: no input
|
# test: no input
|
||||||
@ -225,8 +230,10 @@ async def test_create_entry(
|
|||||||
{
|
{
|
||||||
CONF_PLATFORM: PLATFORM_WEBHOOKS,
|
CONF_PLATFORM: PLATFORM_WEBHOOKS,
|
||||||
CONF_API_KEY: "mock api key",
|
CONF_API_KEY: "mock api key",
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
CONF_PROXY_URL: "invalid",
|
CONF_PROXY_URL: "invalid",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -245,8 +252,10 @@ async def test_create_entry(
|
|||||||
{
|
{
|
||||||
CONF_PLATFORM: PLATFORM_WEBHOOKS,
|
CONF_PLATFORM: PLATFORM_WEBHOOKS,
|
||||||
CONF_API_KEY: "mock api key",
|
CONF_API_KEY: "mock api key",
|
||||||
|
SECTION_ADVANCED_SETTINGS: {
|
||||||
CONF_PROXY_URL: "https://proxy",
|
CONF_PROXY_URL: "https://proxy",
|
||||||
},
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -535,6 +544,7 @@ async def test_duplicate_entry(hass: HomeAssistant) -> None:
|
|||||||
data = {
|
data = {
|
||||||
CONF_PLATFORM: PLATFORM_BROADCAST,
|
CONF_PLATFORM: PLATFORM_BROADCAST,
|
||||||
CONF_API_KEY: "mock api key",
|
CONF_API_KEY: "mock api key",
|
||||||
|
SECTION_ADVANCED_SETTINGS: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -51,6 +51,7 @@ from homeassistant.components.telegram_bot.const import (
|
|||||||
CONF_CONFIG_ENTRY_ID,
|
CONF_CONFIG_ENTRY_ID,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
PLATFORM_BROADCAST,
|
PLATFORM_BROADCAST,
|
||||||
|
SECTION_ADVANCED_SETTINGS,
|
||||||
SERVICE_ANSWER_CALLBACK_QUERY,
|
SERVICE_ANSWER_CALLBACK_QUERY,
|
||||||
SERVICE_DELETE_MESSAGE,
|
SERVICE_DELETE_MESSAGE,
|
||||||
SERVICE_EDIT_CAPTION,
|
SERVICE_EDIT_CAPTION,
|
||||||
@ -722,6 +723,7 @@ async def test_send_message_no_chat_id_error(
|
|||||||
data = {
|
data = {
|
||||||
CONF_PLATFORM: PLATFORM_BROADCAST,
|
CONF_PLATFORM: PLATFORM_BROADCAST,
|
||||||
CONF_API_KEY: "mock api key",
|
CONF_API_KEY: "mock api key",
|
||||||
|
SECTION_ADVANCED_SETTINGS: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch("homeassistant.components.telegram_bot.config_flow.Bot.get_me"):
|
with patch("homeassistant.components.telegram_bot.config_flow.Bot.get_me"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user