mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix samsungtv yaml import without configured name (#51204)
This commit is contained in:
parent
187374c11e
commit
b3d826f2e2
@ -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):
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user