Clean up tradfri import flow (#88588)

This commit is contained in:
Martin Hjelmare 2023-02-22 10:53:48 +01:00 committed by GitHub
parent 93c681ae58
commit 33b16d20b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 38 deletions

View File

@ -108,30 +108,6 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self._host = host
return await self.async_step_auth()
async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult:
"""Import a config entry."""
self._async_abort_entries_match({CONF_HOST: user_input["host"]})
# Happens if user has host directly in configuration.yaml
if "key" not in user_input:
self._host = user_input["host"]
return await self.async_step_auth()
try:
data = await get_gateway_info(
self.hass,
user_input["host"],
# Old config format had a fixed identity
user_input.get("identity", "homeassistant"),
user_input["key"],
)
return await self._entry_from_data(data)
except AuthError:
# If we fail to connect, just pass it on to discovery
self._host = user_input["host"]
return await self.async_step_auth()
async def _entry_from_data(self, data: dict[str, Any]) -> FlowResult:
"""Create an entry from data."""
host = data[CONF_HOST]

View File

@ -164,20 +164,6 @@ async def test_discovery_duplicate_aborted(hass: HomeAssistant) -> None:
assert entry.data["host"] == "new-host"
async def test_import_duplicate_aborted(hass: HomeAssistant) -> None:
"""Test a duplicate import host is ignored."""
MockConfigEntry(domain="tradfri", data={"host": "some-host"}).add_to_hass(hass)
flow = await hass.config_entries.flow.async_init(
"tradfri",
context={"source": config_entries.SOURCE_IMPORT},
data={"host": "some-host"},
)
assert flow["type"] == data_entry_flow.FlowResultType.ABORT
assert flow["reason"] == "already_configured"
async def test_duplicate_discovery(
hass: HomeAssistant, mock_auth, mock_entry_setup
) -> None: