mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Abort other config flows on import (#36608)
* Abort other flows on import * Add test
This commit is contained in:
parent
9311b02369
commit
14bff5a375
@ -59,6 +59,9 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||||||
for flow in in_progress:
|
for flow in in_progress:
|
||||||
self.hass.config_entries.flow.async_abort(flow["flow_id"])
|
self.hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||||
|
|
||||||
|
if self._async_current_entries():
|
||||||
|
return self.async_abort(reason="single_instance_allowed")
|
||||||
|
|
||||||
return self.async_create_entry(title=self._title, data={})
|
return self.async_create_entry(title=self._title, data={})
|
||||||
|
|
||||||
async def async_step_discovery(self, discovery_info):
|
async def async_step_discovery(self, discovery_info):
|
||||||
@ -76,9 +79,14 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
async def async_step_import(self, _):
|
async def async_step_import(self, _):
|
||||||
"""Handle a flow initialized by import."""
|
"""Handle a flow initialized by import."""
|
||||||
if self._async_in_progress() or self._async_current_entries():
|
if self._async_current_entries():
|
||||||
return self.async_abort(reason="single_instance_allowed")
|
return self.async_abort(reason="single_instance_allowed")
|
||||||
|
|
||||||
|
# Cancel other flows.
|
||||||
|
in_progress = self._async_in_progress()
|
||||||
|
for flow in in_progress:
|
||||||
|
self.hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||||
|
|
||||||
return self.async_create_entry(title=self._title, data={})
|
return self.async_create_entry(title=self._title, data={})
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,6 +149,27 @@ async def test_only_one_in_progress(hass, discovery_flow_conf):
|
|||||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_import_abort_discovery(hass, discovery_flow_conf):
|
||||||
|
"""Test import will finish and cancel discovered one."""
|
||||||
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
|
|
||||||
|
# Discovery starts flow
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
"test", context={"source": config_entries.SOURCE_DISCOVERY}, data={}
|
||||||
|
)
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
|
|
||||||
|
# Start import flow
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
"test", context={"source": config_entries.SOURCE_IMPORT}, data={}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
||||||
|
# Discovery flow has been aborted
|
||||||
|
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_import_no_confirmation(hass, discovery_flow_conf):
|
async def test_import_no_confirmation(hass, discovery_flow_conf):
|
||||||
"""Test import requires no confirmation to set up."""
|
"""Test import requires no confirmation to set up."""
|
||||||
flow = config_entries.HANDLERS["test"]()
|
flow = config_entries.HANDLERS["test"]()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user