diff --git a/homeassistant/components/awair/config_flow.py b/homeassistant/components/awair/config_flow.py index 99b1545e792..c68d46f7d39 100644 --- a/homeassistant/components/awair/config_flow.py +++ b/homeassistant/components/awair/config_flow.py @@ -10,7 +10,7 @@ from python_awair.exceptions import AuthError, AwairError from python_awair.user import AwairUser import voluptuous as vol -from homeassistant.components import zeroconf +from homeassistant.components import onboarding, zeroconf from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigFlow from homeassistant.const import CONF_ACCESS_TOKEN, CONF_DEVICE, CONF_HOST from homeassistant.core import callback @@ -60,7 +60,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN): self, user_input: dict[str, Any] | None = None ) -> FlowResult: """Confirm discovery.""" - if user_input is not None: + if user_input is not None or not onboarding.async_is_onboarded(self.hass): title = f"{self._device.model} ({self._device.device_id})" return self.async_create_entry( title=title, diff --git a/tests/components/awair/test_config_flow.py b/tests/components/awair/test_config_flow.py index b939b62641a..aeb7b7d5d8a 100644 --- a/tests/components/awair/test_config_flow.py +++ b/tests/components/awair/test_config_flow.py @@ -399,3 +399,29 @@ async def test_zeroconf_discovery_update_configuration( assert config_entry.data[CONF_HOST] == ZEROCONF_DISCOVERY.host assert mock_setup_entry.call_count == 0 + + +async def test_zeroconf_during_onboarding( + hass: HomeAssistant, local_devices: Any +) -> None: + """Test the zeroconf creates an entry during onboarding.""" + with patch( + "homeassistant.components.awair.async_setup_entry", + return_value=True, + ) as mock_setup_entry, patch( + "python_awair.AwairClient.query", side_effect=[local_devices] + ), patch( + "homeassistant.components.onboarding.async_is_onboarded", + return_value=False, + ): + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_ZEROCONF}, data=ZEROCONF_DISCOVERY + ) + + assert result.get("type") == data_entry_flow.FlowResultType.CREATE_ENTRY + assert result.get("title") == "Awair Element (24947)" + assert "data" in result + assert result["data"][CONF_HOST] == ZEROCONF_DISCOVERY.host + assert "result" in result + assert result["result"].unique_id == LOCAL_UNIQUE_ID + assert len(mock_setup_entry.mock_calls) == 1