diff --git a/homeassistant/components/smlight/config_flow.py b/homeassistant/components/smlight/config_flow.py index e8984300ff1..0e5b0f49d7b 100644 --- a/homeassistant/components/smlight/config_flow.py +++ b/homeassistant/components/smlight/config_flow.py @@ -97,8 +97,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() diff --git a/tests/components/smlight/test_config_flow.py b/tests/components/smlight/test_config_flow.py index dae727c7a29..2fd39f75704 100644 --- a/tests/components/smlight/test_config_flow.py +++ b/tests/components/smlight/test_config_flow.py @@ -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