Skip to content

Commit

Permalink
Don't abort airgradient user flow if flow in progress (#124300)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek committed Aug 24, 2024
1 parent 664e025 commit 7ae8f4c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion homeassistant/components/airgradient/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ async def async_step_user(
except AirGradientError:
errors["base"] = "cannot_connect"
else:
await self.async_set_unique_id(current_measures.serial_number)
await self.async_set_unique_id(
current_measures.serial_number, raise_on_progress=False
)
self._abort_if_unique_id_configured()
await self.set_configuration_source()
return self.async_create_entry(
Expand Down
29 changes: 29 additions & 0 deletions tests/components/airgradient/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,32 @@ async def test_zeroconf_flow_abort_old_firmware(hass: HomeAssistant) -> None:
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "invalid_version"


async def test_user_flow_works_discovery(
hass: HomeAssistant,
mock_new_airgradient_client: AsyncMock,
mock_setup_entry: AsyncMock,
) -> None:
"""Test user flow can continue after discovery happened."""
await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_ZEROCONF},
data=ZEROCONF_DISCOVERY,
)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert len(hass.config_entries.flow.async_progress(DOMAIN)) == 2
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "10.0.0.131"},
)
assert result["type"] is FlowResultType.CREATE_ENTRY

# Verify the discovery flow was aborted
assert not hass.config_entries.flow.async_progress(DOMAIN)

0 comments on commit 7ae8f4c

Please sign in to comment.