diff --git a/homeassistant/components/smtp/__init__.py b/homeassistant/components/smtp/__init__.py index 397bf4953eba..9e66d0536307 100644 --- a/homeassistant/components/smtp/__init__.py +++ b/homeassistant/components/smtp/__init__.py @@ -26,7 +26,14 @@ from homeassistant.helpers import ( from homeassistant.helpers.typing import ConfigType from homeassistant.util.ssl import client_context, client_context_no_verify -from .const import CONF_ENCRYPTION, CONF_ENTRY, CONF_OLD_RECIPIENT, CONF_SERVER, DOMAIN +from .const import ( + CONF_ENCRYPTION, + CONF_ENTRY, + CONF_OLD_RECIPIENT, + CONF_SERVER, + DEFAULT_TIMEOUT, + DOMAIN, +) from .services import async_setup_services _LOGGER = logging.getLogger(__name__) @@ -71,7 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: SmtpConfigEntry) -> bool port=entry.data[CONF_PORT], username=entry.data.get(CONF_USERNAME), password=entry.data.get(CONF_PASSWORD), - timeout=entry.options.get(CONF_TIMEOUT), + timeout=entry.options.get(CONF_TIMEOUT, DEFAULT_TIMEOUT), use_tls=entry.data[CONF_ENCRYPTION] == "tls", start_tls=entry.data[CONF_ENCRYPTION] == "starttls", tls_context=( diff --git a/homeassistant/components/smtp/config_flow.py b/homeassistant/components/smtp/config_flow.py index 61a91ab02ff2..e902be6c4dc8 100644 --- a/homeassistant/components/smtp/config_flow.py +++ b/homeassistant/components/smtp/config_flow.py @@ -65,7 +65,7 @@ _LOGGER = logging.getLogger(__name__) OPTIONS_SCHEMA = vol.Schema( { - vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): vol.All( + vol.Optional(CONF_TIMEOUT): vol.All( NumberSelector( NumberSelectorConfig( min=1, @@ -309,7 +309,7 @@ async def validate_input( port=user_input[CONF_PORT], username=user_input.get(CONF_USERNAME), password=user_input.get(CONF_PASSWORD), - timeout=options.get(CONF_TIMEOUT), + timeout=options.get(CONF_TIMEOUT, DEFAULT_TIMEOUT), use_tls=user_input[CONF_ENCRYPTION] == "tls", start_tls=user_input[CONF_ENCRYPTION] == "starttls", tls_context=( diff --git a/homeassistant/components/smtp/const.py b/homeassistant/components/smtp/const.py index 935d077ea292..e4888fa6b13a 100644 --- a/homeassistant/components/smtp/const.py +++ b/homeassistant/components/smtp/const.py @@ -20,7 +20,7 @@ SECTION_OPTIONS: Final = "options" DEFAULT_HOST: Final = "localhost" DEFAULT_PORT: Final = 587 -DEFAULT_TIMEOUT: Final = 5 +DEFAULT_TIMEOUT: Final = 60 DEFAULT_DEBUG: Final = False DEFAULT_ENCRYPTION: Final = "starttls" diff --git a/homeassistant/components/smtp/strings.json b/homeassistant/components/smtp/strings.json index d5dbfbcd3ec7..d11c74e83751 100644 --- a/homeassistant/components/smtp/strings.json +++ b/homeassistant/components/smtp/strings.json @@ -154,7 +154,7 @@ "timeout": "Connection timeout" }, "data_description": { - "timeout": "Maximum time to wait for a response from the SMTP server before the connection attempt is aborted." + "timeout": "Maximum time to wait for a response from the SMTP server before the connection attempt is aborted. Defaults to 60 seconds." } } } diff --git a/tests/components/smtp/test_config_flow.py b/tests/components/smtp/test_config_flow.py index 211c23b36bde..491ea085583f 100644 --- a/tests/components/smtp/test_config_flow.py +++ b/tests/components/smtp/test_config_flow.py @@ -53,7 +53,7 @@ async def test_form( result["flow_id"], { **USER_INPUT, - SECTION_OPTIONS: {CONF_TIMEOUT: 60}, + SECTION_OPTIONS: {}, }, ) await hass.async_block_till_done() @@ -61,7 +61,7 @@ async def test_form( assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "Home Assistant" assert result["data"] == USER_INPUT - assert result["options"] == {CONF_TIMEOUT: 60} + assert result["options"] == {} assert len(mock_setup_entry.mock_calls) == 1 await hass.async_block_till_done(wait_background_tasks=True)