mirror of https://github.com/home-assistant/core
Explicitly define all methods in ConfigFlow (#49341)
This commit is contained in:
parent
189511724a
commit
7a9385d857
|
@ -92,7 +92,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
_, hub_name = await _validate_input(self.hass, self._discovered)
|
||||
self._discovered[CONF_NAME] = hub_name
|
||||
|
||||
async def async_step_zeroconf( # type: ignore[override]
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> FlowResultDict:
|
||||
"""Handle a flow initialized by zeroconf discovery."""
|
||||
|
|
|
@ -56,10 +56,10 @@ class BroadlinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"host": device.host[0],
|
||||
}
|
||||
|
||||
async def async_step_dhcp(self, dhcp_discovery):
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
"""Handle dhcp discovery."""
|
||||
host = dhcp_discovery[IP_ADDRESS]
|
||||
unique_id = dhcp_discovery[MAC_ADDRESS].lower().replace(":", "")
|
||||
host = discovery_info[IP_ADDRESS]
|
||||
unique_id = discovery_info[MAC_ADDRESS].lower().replace(":", "")
|
||||
await self.async_set_unique_id(unique_id)
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||
try:
|
||||
|
|
|
@ -63,12 +63,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_dhcp(self, dhcp_discovery):
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
"""Handle dhcp discovery."""
|
||||
self.discovered_ip = dhcp_discovery[IP_ADDRESS]
|
||||
await self.async_set_unique_id(format_mac(dhcp_discovery[MAC_ADDRESS]))
|
||||
self.discovered_ip = discovery_info[IP_ADDRESS]
|
||||
await self.async_set_unique_id(format_mac(discovery_info[MAC_ADDRESS]))
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: self.discovered_ip})
|
||||
name = name_short_mac(short_mac(dhcp_discovery[MAC_ADDRESS]))
|
||||
name = name_short_mac(short_mac(discovery_info[MAC_ADDRESS]))
|
||||
self.context["title_placeholders"] = {"name": name}
|
||||
try:
|
||||
self.discovered_info = await fetch_mac_and_title(
|
||||
|
|
|
@ -213,7 +213,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
return self.async_create_entry(title=title, data=user_input)
|
||||
|
||||
async def async_step_ssdp( # type: ignore[override]
|
||||
async def async_step_ssdp(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> FlowResultDict:
|
||||
"""Handle SSDP initiated config flow."""
|
||||
|
|
|
@ -78,30 +78,30 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_homekit(self, homekit_info):
|
||||
async def async_step_homekit(self, discovery_info):
|
||||
"""Handle HomeKit discovery."""
|
||||
|
||||
# If we already have the host configured do
|
||||
# not open connections to it if we can avoid it.
|
||||
if self._host_already_configured(homekit_info[CONF_HOST]):
|
||||
if self._host_already_configured(discovery_info[CONF_HOST]):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
try:
|
||||
info = await validate_input(self.hass, homekit_info)
|
||||
info = await validate_input(self.hass, discovery_info)
|
||||
except CannotConnect:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
await self.async_set_unique_id(info["unique_id"], raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured({CONF_HOST: homekit_info["host"]})
|
||||
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})
|
||||
|
||||
name = homekit_info["name"]
|
||||
name = discovery_info["name"]
|
||||
if name.endswith(HAP_SUFFIX):
|
||||
name = name[: -len(HAP_SUFFIX)]
|
||||
|
||||
self.powerview_config = {
|
||||
CONF_HOST: homekit_info["host"],
|
||||
CONF_HOST: discovery_info["host"],
|
||||
CONF_NAME: name,
|
||||
}
|
||||
return await self.async_step_link()
|
||||
|
|
|
@ -154,7 +154,7 @@ class HyperionConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
return self.async_abort(reason="cannot_connect")
|
||||
return await self._advance_to_auth_step_if_necessary(hyperion_client)
|
||||
|
||||
async def async_step_ssdp(self, discovery_info: dict[str, Any]) -> FlowResultDict: # type: ignore[override]
|
||||
async def async_step_ssdp(self, discovery_info: dict[str, Any]) -> FlowResultDict:
|
||||
"""Handle a flow initiated by SSDP."""
|
||||
# Sample data provided by SSDP: {
|
||||
# 'ssdp_location': 'http://192.168.0.1:8090/description.xml',
|
||||
|
|
|
@ -65,7 +65,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_homekit(self, homekit_info):
|
||||
async def async_step_homekit(self, discovery_info):
|
||||
"""Handle HomeKit discovery."""
|
||||
if self._async_current_entries():
|
||||
# We can see myq on the network to tell them to configure
|
||||
|
@ -76,7 +76,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# add a new one via "+"
|
||||
return self.async_abort(reason="already_configured")
|
||||
properties = {
|
||||
key.lower(): value for (key, value) in homekit_info["properties"].items()
|
||||
key.lower(): value for (key, value) in discovery_info["properties"].items()
|
||||
}
|
||||
await self.async_set_unique_id(properties["id"])
|
||||
return await self.async_step_user()
|
||||
|
|
|
@ -59,12 +59,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Initialize the powerwall flow."""
|
||||
self.ip_address = None
|
||||
|
||||
async def async_step_dhcp(self, dhcp_discovery):
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
"""Handle dhcp discovery."""
|
||||
if self._async_ip_address_already_configured(dhcp_discovery[IP_ADDRESS]):
|
||||
if self._async_ip_address_already_configured(discovery_info[IP_ADDRESS]):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
self.ip_address = dhcp_discovery[IP_ADDRESS]
|
||||
self.ip_address = discovery_info[IP_ADDRESS]
|
||||
self.context["title_placeholders"] = {CONF_IP_ADDRESS: self.ip_address}
|
||||
return await self.async_step_user()
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_homekit(self, homekit_info):
|
||||
async def async_step_homekit(self, discovery_info):
|
||||
"""Handle HomeKit discovery."""
|
||||
if self._async_current_entries():
|
||||
# We can see rachio on the network to tell them to configure
|
||||
|
@ -89,7 +89,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# add a new one via "+"
|
||||
return self.async_abort(reason="already_configured")
|
||||
properties = {
|
||||
key.lower(): value for (key, value) in homekit_info["properties"].items()
|
||||
key.lower(): value for (key, value) in discovery_info["properties"].items()
|
||||
}
|
||||
await self.async_set_unique_id(properties["id"])
|
||||
return await self.async_step_user()
|
||||
|
|
|
@ -78,16 +78,16 @@ class RoombaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Get the options flow for this handler."""
|
||||
return OptionsFlowHandler(config_entry)
|
||||
|
||||
async def async_step_dhcp(self, dhcp_discovery):
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
"""Handle dhcp discovery."""
|
||||
if self._async_host_already_configured(dhcp_discovery[IP_ADDRESS]):
|
||||
if self._async_host_already_configured(discovery_info[IP_ADDRESS]):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
if not dhcp_discovery[HOSTNAME].startswith(("irobot-", "roomba-")):
|
||||
if not discovery_info[HOSTNAME].startswith(("irobot-", "roomba-")):
|
||||
return self.async_abort(reason="not_irobot_device")
|
||||
|
||||
self.host = dhcp_discovery[IP_ADDRESS]
|
||||
self.blid = _async_blid_from_hostname(dhcp_discovery[HOSTNAME])
|
||||
self.host = discovery_info[IP_ADDRESS]
|
||||
self.blid = _async_blid_from_hostname(discovery_info[HOSTNAME])
|
||||
await self.async_set_unique_id(self.blid)
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: self.host})
|
||||
|
||||
|
|
|
@ -89,15 +89,15 @@ class ScreenlogicConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self.discovered_gateways = await async_discover_gateways_by_unique_id(self.hass)
|
||||
return await self.async_step_gateway_select()
|
||||
|
||||
async def async_step_dhcp(self, dhcp_discovery):
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
"""Handle dhcp discovery."""
|
||||
mac = _extract_mac_from_name(dhcp_discovery[HOSTNAME])
|
||||
mac = _extract_mac_from_name(discovery_info[HOSTNAME])
|
||||
await self.async_set_unique_id(mac)
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_IP_ADDRESS: dhcp_discovery[IP_ADDRESS]}
|
||||
updates={CONF_IP_ADDRESS: discovery_info[IP_ADDRESS]}
|
||||
)
|
||||
self.discovered_ip = dhcp_discovery[IP_ADDRESS]
|
||||
self.context["title_placeholders"] = {"name": dhcp_discovery[HOSTNAME]}
|
||||
self.discovered_ip = discovery_info[IP_ADDRESS]
|
||||
self.context["title_placeholders"] = {"name": discovery_info[HOSTNAME]}
|
||||
return await self.async_step_gateway_entry()
|
||||
|
||||
async def async_step_gateway_select(self, user_input=None):
|
||||
|
|
|
@ -146,21 +146,21 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="credentials", data_schema=schema, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_zeroconf(self, zeroconf_info):
|
||||
async def async_step_zeroconf(self, discovery_info):
|
||||
"""Handle zeroconf discovery."""
|
||||
try:
|
||||
self.info = info = await self._async_get_info(zeroconf_info["host"])
|
||||
self.info = info = await self._async_get_info(discovery_info["host"])
|
||||
except HTTP_CONNECT_ERRORS:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except aioshelly.FirmwareUnsupported:
|
||||
return self.async_abort(reason="unsupported_firmware")
|
||||
|
||||
await self.async_set_unique_id(info["mac"])
|
||||
self._abort_if_unique_id_configured({CONF_HOST: zeroconf_info["host"]})
|
||||
self.host = zeroconf_info["host"]
|
||||
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})
|
||||
self.host = discovery_info["host"]
|
||||
|
||||
self.context["title_placeholders"] = {
|
||||
"name": zeroconf_info.get("name", "").split(".")[0]
|
||||
"name": discovery_info.get("name", "").split(".")[0]
|
||||
}
|
||||
|
||||
if info["auth"]:
|
||||
|
|
|
@ -59,19 +59,19 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self.mac = None
|
||||
self.ip_address = None
|
||||
|
||||
async def async_step_dhcp(self, dhcp_discovery):
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
"""Handle dhcp discovery."""
|
||||
if self._host_already_configured(dhcp_discovery[IP_ADDRESS]):
|
||||
if self._host_already_configured(discovery_info[IP_ADDRESS]):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
formatted_mac = format_mac(dhcp_discovery[MAC_ADDRESS])
|
||||
formatted_mac = format_mac(discovery_info[MAC_ADDRESS])
|
||||
await self.async_set_unique_id(format_mac(formatted_mac))
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_HOST: dhcp_discovery[IP_ADDRESS]}
|
||||
updates={CONF_HOST: discovery_info[IP_ADDRESS]}
|
||||
)
|
||||
self.host = dhcp_discovery[HOSTNAME]
|
||||
self.host = discovery_info[HOSTNAME]
|
||||
self.mac = formatted_mac
|
||||
self.ip_address = dhcp_discovery[IP_ADDRESS]
|
||||
self.ip_address = discovery_info[IP_ADDRESS]
|
||||
self.context["title_placeholders"] = {"ip": self.ip_address, "mac": self.mac}
|
||||
return await self.async_step_user()
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_homekit(self, homekit_info):
|
||||
async def async_step_homekit(self, discovery_info):
|
||||
"""Handle HomeKit discovery."""
|
||||
if self._async_current_entries():
|
||||
# We can see tado on the network to tell them to configure
|
||||
|
@ -92,7 +92,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# add a new one via "+"
|
||||
return self.async_abort(reason="already_configured")
|
||||
properties = {
|
||||
key.lower(): value for (key, value) in homekit_info["properties"].items()
|
||||
key.lower(): value for (key, value) in discovery_info["properties"].items()
|
||||
}
|
||||
await self.async_set_unique_id(properties["id"])
|
||||
return await self.async_step_user()
|
||||
|
|
|
@ -31,27 +31,27 @@ class WLEDFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
return await self._handle_config_flow(user_input)
|
||||
|
||||
async def async_step_zeroconf(
|
||||
self, user_input: ConfigType | None = None
|
||||
self, discovery_info: ConfigType | None = None
|
||||
) -> dict[str, Any]:
|
||||
"""Handle zeroconf discovery."""
|
||||
if user_input is None:
|
||||
if discovery_info is None:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
# Hostname is format: wled-livingroom.local.
|
||||
host = user_input["hostname"].rstrip(".")
|
||||
host = discovery_info["hostname"].rstrip(".")
|
||||
name, _ = host.rsplit(".")
|
||||
|
||||
self.context.update(
|
||||
{
|
||||
CONF_HOST: user_input["host"],
|
||||
CONF_HOST: discovery_info["host"],
|
||||
CONF_NAME: name,
|
||||
CONF_MAC: user_input["properties"].get(CONF_MAC),
|
||||
CONF_MAC: discovery_info["properties"].get(CONF_MAC),
|
||||
"title_placeholders": {"name": name},
|
||||
}
|
||||
)
|
||||
|
||||
# Prepare configuration flow
|
||||
return await self._handle_config_flow(user_input, True)
|
||||
return await self._handle_config_flow(discovery_info, True)
|
||||
|
||||
async def async_step_zeroconf_confirm(
|
||||
self, user_input: ConfigType = None
|
||||
|
|
|
@ -134,7 +134,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
step_id="manual", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_hassio(self, discovery_info: dict[str, Any]) -> FlowResultDict: # type: ignore[override]
|
||||
async def async_step_hassio(self, discovery_info: dict[str, Any]) -> FlowResultDict:
|
||||
"""Receive configuration from add-on discovery info.
|
||||
|
||||
This flow is triggered by the Z-Wave JS add-on.
|
||||
|
|
|
@ -1229,12 +1229,41 @@ class ConfigFlow(data_entry_flow.FlowHandler):
|
|||
reason=reason, description_placeholders=description_placeholders
|
||||
)
|
||||
|
||||
async_step_hassio = async_step_discovery
|
||||
async_step_homekit = async_step_discovery
|
||||
async_step_mqtt = async_step_discovery
|
||||
async_step_ssdp = async_step_discovery
|
||||
async_step_zeroconf = async_step_discovery
|
||||
async_step_dhcp = async_step_discovery
|
||||
async def async_step_hassio(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> data_entry_flow.FlowResultDict:
|
||||
"""Handle a flow initialized by HASS IO discovery."""
|
||||
return await self.async_step_discovery(discovery_info)
|
||||
|
||||
async def async_step_homekit(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> data_entry_flow.FlowResultDict:
|
||||
"""Handle a flow initialized by Homekit discovery."""
|
||||
return await self.async_step_discovery(discovery_info)
|
||||
|
||||
async def async_step_mqtt(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> data_entry_flow.FlowResultDict:
|
||||
"""Handle a flow initialized by MQTT discovery."""
|
||||
return await self.async_step_discovery(discovery_info)
|
||||
|
||||
async def async_step_ssdp(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> data_entry_flow.FlowResultDict:
|
||||
"""Handle a flow initialized by SSDP discovery."""
|
||||
return await self.async_step_discovery(discovery_info)
|
||||
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> data_entry_flow.FlowResultDict:
|
||||
"""Handle a flow initialized by Zeroconf discovery."""
|
||||
return await self.async_step_discovery(discovery_info)
|
||||
|
||||
async def async_step_dhcp(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> data_entry_flow.FlowResultDict:
|
||||
"""Handle a flow initialized by DHCP discovery."""
|
||||
return await self.async_step_discovery(discovery_info)
|
||||
|
||||
|
||||
class OptionsFlowManager(data_entry_flow.FlowManager):
|
||||
|
|
Loading…
Reference in New Issue