Show no devices found instead of an unknown error in WeatherFlow discovery (#186005)

This commit is contained in:
Pierre-Etienne Cherière
2026-10-12 20:07:14 +01:00
committed by GitHub
parent 94f3323c93
commit d43ccf6f5d
2 changed files with 32 additions and 2 deletions
@@ -18,6 +18,8 @@ from .const import (
ERROR_MSG_NO_DEVICE_FOUND,
)
DISCOVERY_TIMEOUT = 10
async def _async_can_discover_devices() -> bool:
"""Return if there are devices that can be discovered."""
@@ -30,10 +32,11 @@ async def _async_can_discover_devices() -> bool:
if not future_event.done():
future_event.set_result(None)
async with WeatherFlowListener() as client, asyncio.timeout(10):
async with WeatherFlowListener() as client:
try:
client.on(EVENT_DEVICE_DISCOVERED, _async_found)
await future_event
async with asyncio.timeout(DISCOVERY_TIMEOUT):
await future_event
except TimeoutError:
return False
@@ -87,3 +87,30 @@ async def test_devices_with_various_mocks_errors(
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {}
@pytest.mark.usefixtures("mock_setup_entry")
async def test_no_device_discovered(
hass: HomeAssistant, mock_start: AsyncMock, mock_stop: AsyncMock
) -> None:
"""Test the discovery timeout shows no device found, then finish the flow."""
# The mocked hub is discovered after 0.1 seconds, so it is missed by a
# 0.01 second discovery timeout and found on the retry.
with patch(
"homeassistant.components.weatherflow.config_flow.DISCOVERY_TIMEOUT", 0.01
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"]["base"] == ERROR_MSG_NO_DEVICE_FOUND
result = await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {}