Add option to ignore flows (#30008)

This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-12-18 07:41:01 +01:00
1 parent feb39c39a3
commit 9c7caaa142
6 files changed
+132 -3

No files matched your search

@@ -33,6 +33,7 @@ async def async_setup(hass):
hass.components.websocket_api.async_register_command(config_entries_progress)
hass.components.websocket_api.async_register_command(system_options_list)
hass.components.websocket_api.async_register_command(system_options_update)
hass.components.websocket_api.async_register_command(ignore_config_flow)
return True
@@ -284,3 +285,37 @@ async def system_options_update(hass, connection, msg):
hass.config_entries.async_update_entry(entry, system_options=changes)
connection.send_result(msg["id"], entry.system_options.as_dict())
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command({"type": "config_entries/ignore_flow", "flow_id": str})
async def ignore_config_flow(hass, connection, msg):
"""Ignore a config flow."""
flow = next(
(
flw
for flw in hass.config_entries.flow.async_progress()
if flw["flow_id"] == msg["flow_id"]
),
None,
)
if flow is None:
connection.send_error(
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Config entry not found"
)
return
if "unique_id" not in flow["context"]:
connection.send_error(
msg["id"], "no_unique_id", "Specified flow has no unique ID."
)
return
await hass.config_entries.flow.async_init(
flow["handler"],
context={"source": config_entries.SOURCE_IGNORE},
data={"unique_id": flow["context"]["unique_id"]},
)
connection.send_result(msg["id"])
+1 -1
View File
@@ -75,7 +75,7 @@ class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="no_bridges")
# Find already configured hosts
already_configured = self._async_current_ids()
already_configured = self._async_current_ids(False)
bridges = [bridge for bridge in bridges if bridge.id not in already_configured]
if not bridges:
+11 -1
View File
@@ -24,6 +24,7 @@ SOURCE_IMPORT = "import"
SOURCE_SSDP = "ssdp"
SOURCE_USER = "user"
SOURCE_ZEROCONF = "zeroconf"
SOURCE_IGNORE = "ignore"
HANDLERS = Registry()
@@ -157,6 +158,9 @@ class ConfigEntry:
tries: int = 0,
) -> None:
"""Set up an entry."""
if self.source == SOURCE_IGNORE:
return
if integration is None:
integration = await loader.async_get_integration(hass, self.domain)
@@ -792,12 +796,13 @@ class ConfigFlow(data_entry_flow.FlowHandler):
return self.hass.config_entries.async_entries(self.handler)
@callback
def _async_current_ids(self) -> Set[Optional[str]]:
def _async_current_ids(self, include_ignore: bool = True) -> Set[Optional[str]]:
"""Return current unique IDs."""
assert self.hass is not None
return set(
entry.unique_id
for entry in self.hass.config_entries.async_entries(self.handler)
if include_ignore or entry.source != SOURCE_IGNORE
)
@callback
@@ -810,6 +815,11 @@ class ConfigFlow(data_entry_flow.FlowHandler):
if flw["handler"] == self.handler and flw["flow_id"] != self.flow_id
]
async def async_step_ignore(self, user_input: Dict[str, Any]) -> Dict[str, Any]:
"""Ignore this config flow."""
await self.async_set_unique_id(user_input["unique_id"], raise_on_progress=False)
return self.async_create_entry(title="Ignored", data={})
class OptionsFlowManager:
"""Flow to set options for a configuration entry."""