diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 40d0a4de763..36c68008a8e 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -316,6 +316,9 @@ class FlowManager(abc.ABC): result: FlowResult | None = None while not result or result["type"] == FlowResultType.SHOW_PROGRESS_DONE: result = await self._async_configure(flow_id, user_input) + flow = self._progress.get(flow_id) + if flow and flow.deprecated_show_progress: + break return result async def _async_configure( @@ -540,6 +543,7 @@ class FlowHandler: __progress_task: asyncio.Task[Any] | None = None __no_progress_task_reported = False + deprecated_show_progress = False @property def source(self) -> str | None: @@ -710,6 +714,9 @@ class FlowHandler: report_issue, ) + if progress_task is None: + self.deprecated_show_progress = True + flow_result = FlowResult( type=FlowResultType.SHOW_PROGRESS, flow_id=self.flow_id, diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 78833ac7517..d39c8faccef 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -511,29 +511,31 @@ async def test_show_progress_hidden_from_frontend(hass: HomeAssistant, manager) """Test show progress done is not sent to frontend.""" manager.hass = hass async_show_progress_done_called = False + progress_task: asyncio.Task[None] | None = None @manager.mock_reg_handler("test") class TestFlow(data_entry_flow.FlowHandler): VERSION = 5 data = None - progress_task: asyncio.Task[None] | None = None async def async_step_init(self, user_input=None): + nonlocal progress_task + async def long_running_job() -> None: return - if not self.progress_task: - self.progress_task = hass.async_create_task(long_running_job()) - if self.progress_task.done(): + if not progress_task: + progress_task = hass.async_create_task(long_running_job()) + if progress_task.done(): nonlocal async_show_progress_done_called async_show_progress_done_called = True return self.async_show_progress_done(next_step_id="finish") return self.async_show_progress( step_id="init", progress_action="task", - # Set to None to simulate flow manager has not yet called when - # frontend loads - progress_task=None, + # Set to a task which never finishes to simulate flow manager has not + # yet called when frontend loads + progress_task=hass.async_create_task(asyncio.Event().wait()), ) async def async_step_finish(self, user_input=None): @@ -546,7 +548,7 @@ async def test_show_progress_hidden_from_frontend(hass: HomeAssistant, manager) assert len(manager.async_progress_by_handler("test")) == 1 assert manager.async_get(result["flow_id"])["handler"] == "test" - await hass.async_block_till_done() + await progress_task assert not async_show_progress_done_called # Frontend refreshes the flow @@ -628,8 +630,14 @@ async def test_show_progress_legacy(hass: HomeAssistant, manager, caplog) -> Non result = await manager.async_configure( result["flow_id"], {"task_finished": 2, "title": "Hello"} ) - # Note: The SHOW_PROGRESS_DONE is hidden from frontend; FlowManager automatically - # calls the flow again + # Note: The SHOW_PROGRESS_DONE is not hidden from frontend when flows manage + # the progress tasks themselves + assert result["type"] == data_entry_flow.FlowResultType.SHOW_PROGRESS_DONE + + # Frontend refreshes the flow + result = await manager.async_configure( + result["flow_id"], {"task_finished": 2, "title": "Hello"} + ) assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY assert result["title"] == "Hello"