Abort zeroconf flow on connect error during discovery (#125980)

Abort zereconf flow on connect error during discovery
This commit is contained in:
TimL 2024-09-16 21:45:39 +10:00 committed by Franck Nijhof
parent c4eca4469f
commit fae26ee5da
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 22 additions and 1 deletions

View file

@ -94,8 +94,13 @@ class SmlightConfigFlow(ConfigFlow, domain=DOMAIN):
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()

View file

@ -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