ConfigFlow default discovery without unique ID (#36754)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-06-15 13:38:38 +02:00
1 parent dfac9c5e03
commit 3cc94f7d6a
32 files changed
+408 -170

No files matched your search

+4 -1
View File
@@ -4,5 +4,8 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/abode",
"requirements": ["abodepy==0.19.0"],
"codeowners": ["@shred86"]
"codeowners": ["@shred86"],
"homekit": {
"models": ["Abode", "Iota"]
}
}
@@ -105,7 +105,7 @@ class AdGuardHomeFlowHandler(ConfigFlow):
},
)
async def async_step_hassio(self, user_input=None):
async def async_step_hassio(self, discovery_info):
"""Prepare configuration for a Hass.io AdGuard Home add-on.
This flow is triggered by the discovery component.
@@ -113,14 +113,14 @@ class AdGuardHomeFlowHandler(ConfigFlow):
entries = self._async_current_entries()
if not entries:
self._hassio_discovery = user_input
self._hassio_discovery = discovery_info
return await self.async_step_hassio_confirm()
cur_entry = entries[0]
if (
cur_entry.data[CONF_HOST] == user_input[CONF_HOST]
and cur_entry.data[CONF_PORT] == user_input[CONF_PORT]
cur_entry.data[CONF_HOST] == discovery_info[CONF_HOST]
and cur_entry.data[CONF_PORT] == discovery_info[CONF_PORT]
):
return self.async_abort(reason="single_instance_allowed")
@@ -133,8 +133,8 @@ class AdGuardHomeFlowHandler(ConfigFlow):
cur_entry,
data={
**cur_entry.data,
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input[CONF_PORT],
CONF_HOST: discovery_info[CONF_HOST],
CONF_PORT: discovery_info[CONF_PORT],
},
)
@@ -23,13 +23,13 @@ class AgentFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Initialize the Agent config flow."""
self.device_config = {}
async def async_step_user(self, info=None):
async def async_step_user(self, user_input=None):
"""Handle an Agent config flow."""
errors = {}
if info is not None:
host = info[CONF_HOST]
port = info[CONF_PORT]
if user_input is not None:
host = user_input[CONF_HOST]
port = user_input[CONF_PORT]
server_origin = generate_url(host, port)
agent_client = Agent(server_origin, async_get_clientsession(self.hass))
@@ -48,8 +48,8 @@ class AgentFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self._abort_if_unique_id_configured(
updates={
CONF_HOST: info[CONF_HOST],
CONF_PORT: info[CONF_PORT],
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input[CONF_PORT],
SERVER_URL: server_origin,
}
)
@@ -94,12 +94,12 @@ class AlmondFlowHandler(config_entry_oauth2_flow.AbstractOAuth2FlowHandler):
data={"type": TYPE_LOCAL, "host": user_input["host"]},
)
async def async_step_hassio(self, user_input=None):
async def async_step_hassio(self, discovery_info):
"""Receive a Hass.io discovery."""
if self._async_current_entries():
return self.async_abort(reason="already_setup")
self.hassio_discovery = user_input
self.hassio_discovery = discovery_info
return await self.async_step_hassio_confirm()
@@ -45,21 +45,21 @@ class ArcamFmjFlowHandler(config_entries.ConfigFlow):
title=f"{DEFAULT_NAME} ({host})", data={CONF_HOST: host, CONF_PORT: port},
)
async def async_step_user(self, user_info=None):
async def async_step_user(self, user_input=None):
"""Handle a discovered device."""
errors = {}
if user_info is not None:
if user_input is not None:
uuid = await get_uniqueid_from_host(
async_get_clientsession(self.hass), user_info[CONF_HOST]
async_get_clientsession(self.hass), user_input[CONF_HOST]
)
if uuid:
await self._async_set_unique_id_and_update(
user_info[CONF_HOST], user_info[CONF_PORT], uuid
user_input[CONF_HOST], user_input[CONF_PORT], uuid
)
return await self._async_check_and_create(
user_info[CONF_HOST], user_info[CONF_PORT]
user_input[CONF_HOST], user_input[CONF_PORT]
)
fields = {
@@ -69,16 +69,18 @@ class BrotherConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)
async def async_step_zeroconf(self, user_input=None):
async def async_step_zeroconf(self, discovery_info):
"""Handle zeroconf discovery."""
if user_input is None:
if discovery_info is None:
return self.async_abort(reason="connection_error")
if not user_input.get("name") or not user_input["name"].startswith("Brother"):
if not discovery_info.get("name") or not discovery_info["name"].startswith(
"Brother"
):
return self.async_abort(reason="not_brother_printer")
# Hostname is format: brother.local.
self.host = user_input["hostname"].rstrip(".")
self.host = discovery_info["hostname"].rstrip(".")
self.brother = Brother(self.host)
try:
@@ -128,7 +128,7 @@ class FlowHandler(config_entries.ConfigFlow):
async def async_step_zeroconf(self, discovery_info):
"""Prepare configuration for a discovered Daikin device."""
_LOGGER.debug("Zeroconf discovery_info: %s", discovery_info)
_LOGGER.debug("Zeroconf user_input: %s", discovery_info)
devices = Discovery.poll(discovery_info[CONF_HOST])
await self.async_set_unique_id(next(iter(devices.values()))[KEY_MAC])
self._abort_if_unique_id_configured()
@@ -205,25 +205,25 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return await self.async_step_link()
async def async_step_hassio(self, user_input=None):
async def async_step_hassio(self, discovery_info):
"""Prepare configuration for a Hass.io deCONZ bridge.
This flow is triggered by the discovery component.
"""
LOGGER.debug("deCONZ HASSIO discovery %s", pformat(user_input))
LOGGER.debug("deCONZ HASSIO discovery %s", pformat(discovery_info))
self.bridge_id = normalize_bridge_id(user_input[CONF_SERIAL])
self.bridge_id = normalize_bridge_id(discovery_info[CONF_SERIAL])
await self.async_set_unique_id(self.bridge_id)
self._abort_if_unique_id_configured(
updates={
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input[CONF_PORT],
CONF_API_KEY: user_input[CONF_API_KEY],
CONF_HOST: discovery_info[CONF_HOST],
CONF_PORT: discovery_info[CONF_PORT],
CONF_API_KEY: discovery_info[CONF_API_KEY],
}
)
self._hassio_discovery = user_input
self._hassio_discovery = discovery_info
return await self.async_step_hassio_confirm()
@@ -29,7 +29,7 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
async def async_step_user(
self, user_input: Optional[ConfigType] = None, error: Optional[str] = None
):
): # pylint: disable=arguments-differ
"""Handle a flow initialized by the user."""
if user_input is not None:
return await self._async_authenticate_or_add(user_input)
@@ -55,7 +55,7 @@ class FlickConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
else:
return token is not None
async def async_step_user(self, user_input):
async def async_step_user(self, user_input=None):
"""Handle gathering login info."""
errors = {}
if user_input is not None:
@@ -105,6 +105,6 @@ class FreeboxFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Import a config entry."""
return await self.async_step_user(user_input)
async def async_step_discovery(self, user_input=None):
async def async_step_discovery(self, discovery_info):
"""Initialize step from discovery."""
return await self.async_step_user(user_input)
return await self.async_step_user(discovery_info)
@@ -110,12 +110,12 @@ class FritzboxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=DATA_SCHEMA_USER, errors=errors
)
async def async_step_ssdp(self, user_input):
async def async_step_ssdp(self, discovery_info):
"""Handle a flow initialized by discovery."""
host = urlparse(user_input[ATTR_SSDP_LOCATION]).hostname
host = urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname
self.context[CONF_HOST] = host
uuid = user_input.get(ATTR_UPNP_UDN)
uuid = discovery_info.get(ATTR_UPNP_UDN)
if uuid:
if uuid.startswith("uuid:"):
uuid = uuid[5:]
@@ -134,7 +134,7 @@ class FritzboxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="already_configured")
self._host = host
self._name = user_input.get(ATTR_UPNP_FRIENDLY_NAME) or host
self._name = discovery_info.get(ATTR_UPNP_FRIENDLY_NAME) or host
self.context["title_placeholders"] = {"name": self._name}
return await self.async_step_confirm()
@@ -80,7 +80,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
title=info[CONF_UID], data={CONF_UID: info["uid"], **user_input}
)
async def async_step_zeroconf(self, discovery_info=None):
async def async_step_zeroconf(self, discovery_info):
"""Handle the configuration via zeroconf."""
if discovery_info is None:
return self.async_abort(reason="connection_error")
+9 -8
View File
@@ -152,16 +152,17 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
_LOGGER.debug(
"Unable to determine unique id from discovery info and IPP response"
)
return self.async_abort(reason="unique_id_required")
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured(
updates={
CONF_HOST: self.discovery_info[CONF_HOST],
CONF_NAME: self.discovery_info[CONF_NAME],
},
)
if unique_id:
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured(
updates={
CONF_HOST: self.discovery_info[CONF_HOST],
CONF_NAME: self.discovery_info[CONF_NAME],
},
)
await self._async_handle_discovery_without_unique_id()
return await self.async_step_zeroconf_confirm()
async def async_step_zeroconf_confirm(
+2 -2
View File
@@ -74,12 +74,12 @@ class FlowHandler(config_entries.ConfigFlow):
return self.async_create_entry(title="configuration.yaml", data={})
async def async_step_hassio(self, user_input=None):
async def async_step_hassio(self, discovery_info):
"""Receive a Hass.io discovery."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
self._hassio_discovery = user_input
self._hassio_discovery = discovery_info
return await self.async_step_hassio_confirm()
@@ -68,9 +68,9 @@ class OpenThermGwConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self._show_form()
async def async_step_user(self, info=None):
async def async_step_user(self, user_input=None):
"""Handle manual initiation of the config flow."""
return await self.async_step_init(info)
return await self.async_step_init(user_input)
async def async_step_import(self, import_config):
"""
+3 -1
View File
@@ -96,7 +96,9 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.client_id = None
self._manual = False
async def async_step_user(self, user_input=None, errors=None):
async def async_step_user(
self, user_input=None, errors=None
): # pylint: disable=arguments-differ
"""Handle a flow initialized by the user."""
if user_input is not None:
return await self.async_step_plex_website_auth()
@@ -116,17 +116,17 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
async def async_step_ssdp(self, user_input=None):
async def async_step_ssdp(self, discovery_info):
"""Handle a flow initialized by discovery."""
host = urlparse(user_input[ATTR_SSDP_LOCATION]).hostname
host = urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname
ip_address = await self.hass.async_add_executor_job(_get_ip, host)
self._host = host
self._ip = self.context[CONF_IP_ADDRESS] = ip_address
self._manufacturer = user_input.get(ATTR_UPNP_MANUFACTURER)
self._model = user_input.get(ATTR_UPNP_MODEL_NAME)
self._manufacturer = discovery_info.get(ATTR_UPNP_MANUFACTURER)
self._model = discovery_info.get(ATTR_UPNP_MODEL_NAME)
self._name = f"Samsung {self._model}"
self._id = user_input.get(ATTR_UPNP_UDN)
self._id = discovery_info.get(ATTR_UPNP_UDN)
self._title = self._model
# probably access denied
@@ -114,13 +114,14 @@ class FlowHandler(config_entries.ConfigFlow):
},
)
async def async_step_discovery(self, user_input):
async def async_step_discovery(self, discovery_info):
"""Run when a Tellstick is discovered."""
await self._async_handle_discovery_without_unique_id()
_LOGGER.info("Discovered tellstick device: %s", user_input)
if supports_local_api(user_input[1]):
_LOGGER.info("%s support local API", user_input[1])
self._hosts.append(user_input[0])
_LOGGER.info("Discovered tellstick device: %s", discovery_info)
if supports_local_api(discovery_info[1]):
_LOGGER.info("%s support local API", discovery_info[1])
self._hosts.append(discovery_info[0])
return await self.async_step_user()
@@ -1,7 +1,7 @@
{
"config": {
"abort": {
"already_setup": "TelldusLive is already configured",
"already_configured": "TelldusLive is already configured",
"authorize_url_fail": "Unknown error generating an authorize url.",
"authorize_url_timeout": "Timeout generating authorize url.",
"unknown": "Unknown error occurred"
@@ -22,4 +22,4 @@
}
}
}
}
}
@@ -82,12 +82,12 @@ class FlowHandler(config_entries.ConfigFlow):
step_id="auth", data_schema=vol.Schema(fields), errors=errors
)
async def async_step_homekit(self, user_input):
async def async_step_homekit(self, discovery_info):
"""Handle homekit discovery."""
await self.async_set_unique_id(user_input["properties"]["id"])
self._abort_if_unique_id_configured({CONF_HOST: user_input["host"]})
await self.async_set_unique_id(discovery_info["properties"]["id"])
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})
host = user_input["host"]
host = discovery_info["host"]
for entry in self._async_current_entries():
if entry.data[CONF_HOST] != host:
@@ -96,7 +96,7 @@ class FlowHandler(config_entries.ConfigFlow):
# Backwards compat, we update old entries
if not entry.unique_id:
self.hass.config_entries.async_update_entry(
entry, unique_id=user_input["properties"]["id"]
entry, unique_id=discovery_info["properties"]["id"]
)
return self.async_abort(reason="already_configured")