Not slugify cert_expiry name (#28055)

This commit is contained in:
Quentame 2019-10-21 14:30:49 +02:00 committed by Franck Nijhof
parent 6ba437d83a
commit ac467d0b3f
2 changed files with 12 additions and 12 deletions

View File

@ -5,7 +5,6 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_PORT, CONF_NAME, CONF_HOST
from homeassistant.core import HomeAssistant, callback
from homeassistant.util import slugify
from .const import DOMAIN, DEFAULT_PORT, DEFAULT_NAME
from .helper import get_cert
@ -62,11 +61,12 @@ class CertexpiryConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._errors[CONF_HOST] = "host_port_exists"
else:
if await self._test_connection(user_input):
host = user_input[CONF_HOST]
name = slugify(user_input.get(CONF_NAME, DEFAULT_NAME))
prt = user_input.get(CONF_PORT, DEFAULT_PORT)
return self.async_create_entry(
title=name, data={CONF_HOST: host, CONF_PORT: prt}
title=user_input.get(CONF_NAME, DEFAULT_NAME),
data={
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input.get(CONF_PORT, DEFAULT_PORT),
},
)
else:
user_input = {}

View File

@ -5,7 +5,7 @@ from unittest.mock import patch
from homeassistant import data_entry_flow
from homeassistant.components.cert_expiry import config_flow
from homeassistant.components.cert_expiry.const import DEFAULT_PORT
from homeassistant.components.cert_expiry.const import DEFAULT_NAME, DEFAULT_PORT
from homeassistant.const import CONF_PORT, CONF_NAME, CONF_HOST
from tests.common import MockConfigEntry, mock_coro
@ -45,7 +45,7 @@ async def test_user(hass, test_connect):
{CONF_NAME: NAME, CONF_HOST: HOST, CONF_PORT: PORT}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "cert_expiry_test_1_2_3"
assert result["title"] == NAME
assert result["data"][CONF_HOST] == HOST
assert result["data"][CONF_PORT] == PORT
@ -57,21 +57,21 @@ async def test_import(hass, test_connect):
# import with only host
result = await flow.async_step_import({CONF_HOST: HOST})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "ssl_certificate_expiry"
assert result["title"] == DEFAULT_NAME
assert result["data"][CONF_HOST] == HOST
assert result["data"][CONF_PORT] == DEFAULT_PORT
# import with host and name
result = await flow.async_step_import({CONF_HOST: HOST, CONF_NAME: NAME})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "cert_expiry_test_1_2_3"
assert result["title"] == NAME
assert result["data"][CONF_HOST] == HOST
assert result["data"][CONF_PORT] == DEFAULT_PORT
# improt with host and port
result = await flow.async_step_import({CONF_HOST: HOST, CONF_PORT: PORT})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "ssl_certificate_expiry"
assert result["title"] == DEFAULT_NAME
assert result["data"][CONF_HOST] == HOST
assert result["data"][CONF_PORT] == PORT
@ -80,7 +80,7 @@ async def test_import(hass, test_connect):
{CONF_HOST: HOST, CONF_PORT: PORT, CONF_NAME: NAME}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "cert_expiry_test_1_2_3"
assert result["title"] == NAME
assert result["data"][CONF_HOST] == HOST
assert result["data"][CONF_PORT] == PORT
@ -112,7 +112,7 @@ async def test_abort_if_already_setup(hass, test_connect):
{CONF_HOST: HOST, CONF_NAME: NAME, CONF_PORT: 888}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "cert_expiry_test_1_2_3"
assert result["title"] == NAME
assert result["data"][CONF_HOST] == HOST
assert result["data"][CONF_PORT] == 888