Skip to content

Commit

Permalink
Abort zeroconf flow on connect error during discovery (#125980)
Browse files Browse the repository at this point in the history
Abort zereconf flow on connect error during discovery
  • Loading branch information
tl-sl authored Sep 16, 2024
1 parent fdc58f9 commit ac17020
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion homeassistant/components/smlight/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ async def async_step_zeroconf(
mac = discovery_info.properties.get("mac")
# fallback for legacy firmware
if mac is None:
info = await self.client.get_info()
try:
info = await self.client.get_info()
except SmlightConnectionError:
# User is likely running unsupported ESPHome firmware
return self.async_abort(reason="cannot_connect")
mac = info.MAC

await self.async_set_unique_id(format_mac(mac))
self._abort_if_unique_id_configured()

Expand Down
16 changes: 16 additions & 0 deletions tests/components/smlight/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ async def test_zeroconf_cannot_connect(
assert result2["reason"] == "cannot_connect"


async def test_zeroconf_legacy_cannot_connect(
hass: HomeAssistant, mock_smlight_client: MagicMock
) -> None:
"""Test we abort flow on zeroconf discovery unsupported firmware."""
mock_smlight_client.get_info.side_effect = SmlightConnectionError

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=DISCOVERY_INFO_LEGACY,
)

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"


@pytest.mark.usefixtures("mock_smlight_client")
async def test_zeroconf_legacy_mac(
hass: HomeAssistant, mock_smlight_client: MagicMock, mock_setup_entry: AsyncMock
Expand Down

0 comments on commit ac17020

Please sign in to comment.