Fix FlowHandler show progress (#108586)
This commit is contained in:
parent
0566ceca0f
commit
e90b42d3d0
2 changed files with 25 additions and 10 deletions
|
@ -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"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue