Fix samsungtv yaml import without configured name (#51204)

This commit is contained in:
J. Nick Koston 2021-05-28 09:06:17 -05:00 committed by GitHub
parent 187374c11e
commit b3d826f2e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -173,7 +173,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
)
except socket.gaierror as err:
raise data_entry_flow.AbortFlow(RESULT_UNKNOWN_HOST) from err
self._name = user_input[CONF_NAME]
self._name = user_input.get(CONF_NAME, self._host)
self._title = self._name
async def async_step_user(self, user_input=None):

View File

@ -54,6 +54,9 @@ MOCK_IMPORT_DATA = {
CONF_NAME: "fake",
CONF_PORT: 55000,
}
MOCK_IMPORT_DATA_WITHOUT_NAME = {
CONF_HOST: "fake_host",
}
MOCK_IMPORT_WSDATA = {
CONF_HOST: "fake_host",
CONF_NAME: "fake",
@ -509,6 +512,26 @@ async def test_import_legacy(hass: HomeAssistant):
assert result["result"].unique_id is None
async def test_import_legacy_without_name(hass: HomeAssistant):
"""Test importing from yaml without a name."""
with patch(
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
return_value="fake_host",
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=MOCK_IMPORT_DATA_WITHOUT_NAME,
)
await hass.async_block_till_done()
assert result["type"] == "create_entry"
assert result["title"] == "fake_host"
assert result["data"][CONF_METHOD] == METHOD_LEGACY
assert result["data"][CONF_HOST] == "fake_host"
assert result["data"][CONF_MANUFACTURER] == "Samsung"
assert result["result"].unique_id is None
async def test_import_websocket(hass: HomeAssistant):
"""Test importing from yaml with hostname."""
with patch(