Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/bond/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def _async_try_automatic_configure(self) -> None:
_, 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."""
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/broadlink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ async def async_set_device(self, device, raise_on_progress=True):
"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:
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/emonitor/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ async def async_step_user(self, user_input=None):
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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/huawei_lte/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def get_router_title(conn: Connection) -> str:

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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,30 @@ async def async_step_user(self, user_input=None):
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()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hyperion/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def async_step_reauth(
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',
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/myq/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def async_step_user(self, user_input=None):
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
Expand All @@ -76,7 +76,7 @@ async def async_step_homekit(self, homekit_info):
# 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()
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/powerwall/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def __init__(self):
"""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()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/rachio/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def async_step_user(self, user_input=None):
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
Expand All @@ -89,7 +89,7 @@ async def async_step_homekit(self, homekit_info):
# 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()
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/roomba/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ def async_get_options_flow(config_entry):
"""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})

Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/screenlogic/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ async def async_step_user(self, user_input=None):
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):
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/shelly/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ async def async_step_credentials(self, user_input=None):
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"]:
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/somfy_mylink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ def __init__(self):
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()

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/tado/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def async_step_user(self, user_input=None):
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
Expand All @@ -92,7 +92,7 @@ async def async_step_homekit(self, homekit_info):
# 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()
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/wled/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ async def async_step_user(
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discovery info should never be None.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can address this in a follow up too if wanted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know. The typing in that component is already pretty broken and it's not checked anyway. So I think right now it's not worth fixing it before we can enable type checks here. That I'm trying to do in #49270

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah, let's annotate this method correctly at least.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's fix this separately then.

) -> 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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zwave_js/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def async_step_manual(
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.
Expand Down
41 changes: 35 additions & 6 deletions homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,12 +1229,41 @@ def async_abort(
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):
Expand Down