1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Abort other config flows on import (#36608)

* Abort other flows on import

* Add test
This commit is contained in:
Erik Montnemery
2020-06-10 22:46:14 +02:00
committed by GitHub
parent 9311b02369
commit 14bff5a375
2 changed files with 30 additions and 1 deletions

View File

@@ -59,6 +59,9 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
for flow in in_progress:
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={})
async def async_step_discovery(self, discovery_info):
@@ -76,9 +79,14 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
async def async_step_import(self, _):
"""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")
# 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={})