diff --git a/homeassistant/components/elkm1/config_flow.py b/homeassistant/components/elkm1/config_flow.py index 919aad3d012..f8cfdbe9851 100644 --- a/homeassistant/components/elkm1/config_flow.py +++ b/homeassistant/components/elkm1/config_flow.py @@ -25,12 +25,17 @@ from .const import CONF_AUTO_CONFIGURE, DOMAIN _LOGGER = logging.getLogger(__name__) -PROTOCOL_MAP = {"secure": "elks://", "non-secure": "elk://", "serial": "serial://"} +PROTOCOL_MAP = { + "secure": "elks://", + "TLS 1.2": "elksv1_2://", + "non-secure": "elk://", + "serial": "serial://", +} DATA_SCHEMA = vol.Schema( { vol.Required(CONF_PROTOCOL, default="secure"): vol.In( - ["secure", "non-secure", "serial"] + ["secure", "TLS 1.2", "non-secure", "serial"] ), vol.Required(CONF_ADDRESS): str, vol.Optional(CONF_USERNAME, default=""): str, @@ -55,7 +60,7 @@ async def validate_input(data): prefix = data[CONF_PREFIX] url = _make_url_from_data(data) - requires_password = url.startswith("elks://") + requires_password = url.startswith("elks://") or url.startswith("elksv1_2") if requires_password and (not userid or not password): raise InvalidAuth diff --git a/tests/components/elkm1/test_config_flow.py b/tests/components/elkm1/test_config_flow.py index a84ff0351d5..d0498496bf2 100644 --- a/tests/components/elkm1/test_config_flow.py +++ b/tests/components/elkm1/test_config_flow.py @@ -70,6 +70,53 @@ async def test_form_user_with_secure_elk(hass): assert len(mock_setup_entry.mock_calls) == 1 +async def test_form_user_with_tls_elk(hass): + """Test we can setup a secure elk.""" + await setup.async_setup_component(hass, "persistent_notification", {}) + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + assert result["type"] == "form" + assert result["errors"] == {} + + mocked_elk = mock_elk(invalid_auth=False, sync_complete=True) + + with patch( + "homeassistant.components.elkm1.config_flow.elkm1.Elk", + return_value=mocked_elk, + ), patch( + "homeassistant.components.elkm1.async_setup", return_value=True + ) as mock_setup, patch( + "homeassistant.components.elkm1.async_setup_entry", + return_value=True, + ) as mock_setup_entry: + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + "protocol": "TLS 1.2", + "address": "1.2.3.4", + "username": "test-username", + "password": "test-password", + "temperature_unit": "°F", + "prefix": "", + }, + ) + await hass.async_block_till_done() + + assert result2["type"] == "create_entry" + assert result2["title"] == "ElkM1" + assert result2["data"] == { + "auto_configure": True, + "host": "elksv1_2://1.2.3.4", + "password": "test-password", + "prefix": "", + "temperature_unit": "°F", + "username": "test-username", + } + assert len(mock_setup.mock_calls) == 1 + assert len(mock_setup_entry.mock_calls) == 1 + + async def test_form_user_with_non_secure_elk(hass): """Test we can setup a non-secure elk.""" await setup.async_setup_component(hass, "persistent_notification", {})