Fix unbound local variable in Acmeda config flow (#145729)

This commit is contained in:
Joost Lekkerkerker 2025-05-27 19:29:04 +02:00 committed by GitHub
parent 07fd1f99df
commit 4300e846e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -40,9 +40,10 @@ class AcmedaFlowHandler(ConfigFlow, domain=DOMAIN):
entry.unique_id for entry in self._async_current_entries()
}
hubs: list[aiopulse.Hub] = []
with suppress(TimeoutError):
async with timeout(5):
hubs: list[aiopulse.Hub] = [
hubs = [
hub
async for hub in aiopulse.Hub.discover()
if hub.id not in already_configured

View File

@ -49,6 +49,21 @@ async def test_show_form_no_hubs(hass: HomeAssistant, mock_hub_discover) -> None
assert len(mock_hub_discover.mock_calls) == 1
async def test_timeout_fetching_hub(hass: HomeAssistant, mock_hub_discover) -> None:
"""Test that flow aborts if no hubs are discovered."""
mock_hub_discover.side_effect = TimeoutError
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "no_devices_found"
# Check we performed the discovery
assert len(mock_hub_discover.mock_calls) == 1
@pytest.mark.usefixtures("mock_hub_run")
async def test_show_form_one_hub(hass: HomeAssistant, mock_hub_discover) -> None:
"""Test that a config is created when one hub discovered."""