ConfigFlow default discovery without unique ID (#36754)
This commit is contained in:
parent
dfac9c5e03
commit
3cc94f7d6a
32 changed files with 408 additions and 170 deletions
|
@ -1,5 +1,5 @@
|
|||
"""Helpers for data entry flows for config entries."""
|
||||
from typing import Awaitable, Callable, Union
|
||||
from typing import Any, Awaitable, Callable, Dict, Optional, Union
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
||||
|
@ -28,7 +28,9 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||
self._discovery_function = discovery_function
|
||||
self.CONNECTION_CLASS = connection_class # pylint: disable=invalid-name
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: Optional[Dict[str, Any]] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Handle a flow initialized by the user."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="single_instance_allowed")
|
||||
|
@ -37,7 +39,9 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
return await self.async_step_confirm()
|
||||
|
||||
async def async_step_confirm(self, user_input=None):
|
||||
async def async_step_confirm(
|
||||
self, user_input: Optional[Dict[str, Any]] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Confirm setup."""
|
||||
if user_input is None:
|
||||
return self.async_show_form(step_id="confirm")
|
||||
|
@ -48,7 +52,7 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
has_devices = in_progress
|
||||
if not has_devices:
|
||||
has_devices = await self.hass.async_add_job(
|
||||
has_devices = await self.hass.async_add_job( # type: ignore
|
||||
self._discovery_function, self.hass
|
||||
)
|
||||
|
||||
|
@ -56,6 +60,7 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||
return self.async_abort(reason="no_devices_found")
|
||||
|
||||
# Cancel the discovered one.
|
||||
assert self.hass is not None
|
||||
for flow in in_progress:
|
||||
self.hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||
|
||||
|
@ -64,7 +69,9 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
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: Dict[str, Any]
|
||||
) -> Dict[str, Any]:
|
||||
"""Handle a flow initialized by discovery."""
|
||||
if self._async_in_progress() or self._async_current_entries():
|
||||
return self.async_abort(reason="single_instance_allowed")
|
||||
|
@ -77,12 +84,13 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
|
|||
async_step_ssdp = async_step_discovery
|
||||
async_step_homekit = async_step_discovery
|
||||
|
||||
async def async_step_import(self, _):
|
||||
async def async_step_import(self, _: Optional[Dict[str, Any]]) -> Dict[str, Any]:
|
||||
"""Handle a flow initialized by import."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="single_instance_allowed")
|
||||
|
||||
# Cancel other flows.
|
||||
assert self.hass is not None
|
||||
in_progress = self._async_in_progress()
|
||||
for flow in in_progress:
|
||||
self.hass.config_entries.flow.async_abort(flow["flow_id"])
|
||||
|
@ -125,7 +133,9 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
|
|||
self._description_placeholder = description_placeholder
|
||||
self._allow_multiple = allow_multiple
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: Optional[Dict[str, Any]] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Handle a user initiated set up flow to create a webhook."""
|
||||
if not self._allow_multiple and self._async_current_entries():
|
||||
return self.async_abort(reason="one_instance_allowed")
|
||||
|
@ -133,6 +143,7 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
|
|||
if user_input is None:
|
||||
return self.async_show_form(step_id="user")
|
||||
|
||||
assert self.hass is not None
|
||||
webhook_id = self.hass.components.webhook.async_generate_id()
|
||||
|
||||
if (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue