mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
Clean up tradfri import flow (#88588)
This commit is contained in:
parent
93c681ae58
commit
33b16d20b1
@ -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]
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user