mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 11:33:11 -04:00
Add translation_domain to async_show_progress (#194519)
This commit is contained in:
@@ -873,8 +873,13 @@ class FlowHandler(Generic[_FlowContextT, _FlowResultT, _HandlerT]):
|
||||
progress_action: str,
|
||||
description_placeholders: Mapping[str, str] | None = None,
|
||||
progress_task: asyncio.Task[Any] | None = None,
|
||||
translation_domain: str | None = None,
|
||||
) -> _FlowResultT:
|
||||
"""Show a progress message to the user, without user input allowed."""
|
||||
"""Show a progress message to the user, without user input allowed.
|
||||
|
||||
Pass `translation_domain` to resolve the progress action from another
|
||||
integration's translations instead of the one owning the flow.
|
||||
"""
|
||||
if progress_task is None and not self.__no_progress_task_reported:
|
||||
self.__no_progress_task_reported = True
|
||||
cls = self.__class__
|
||||
@@ -901,6 +906,8 @@ class FlowHandler(Generic[_FlowContextT, _FlowResultT, _HandlerT]):
|
||||
description_placeholders=description_placeholders,
|
||||
progress_task=progress_task,
|
||||
)
|
||||
if translation_domain is not None:
|
||||
flow_result["translation_domain"] = translation_domain
|
||||
if step_id is not None:
|
||||
flow_result["step_id"] = step_id
|
||||
else:
|
||||
|
||||
@@ -1005,7 +1005,7 @@ class AbstractOAuth2DeviceFlowHandler(AbstractOAuth2BaseFlowHandler, metaclass=A
|
||||
self.flow_impl.async_check_device_activation(self._device_authorization)
|
||||
)
|
||||
|
||||
result = self.async_show_progress(
|
||||
return self.async_show_progress(
|
||||
step_id="device_flow",
|
||||
progress_action="wait_for_device",
|
||||
description_placeholders={
|
||||
@@ -1018,10 +1018,9 @@ class AbstractOAuth2DeviceFlowHandler(AbstractOAuth2BaseFlowHandler, metaclass=A
|
||||
"code": self._device_authorization.user_code,
|
||||
},
|
||||
progress_task=self._login_task,
|
||||
# The progress string is shared, like the abort reasons
|
||||
translation_domain=HOMEASSISTANT_DOMAIN,
|
||||
)
|
||||
# The progress string is shared, like the abort reasons
|
||||
result["translation_domain"] = HOMEASSISTANT_DOMAIN
|
||||
return result
|
||||
|
||||
async def async_step_device_flow_complete(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
|
||||
@@ -682,6 +682,38 @@ async def test_show_progress(hass: HomeAssistant, manager: MockFlowManager) -> N
|
||||
assert result["title"] == "Hello"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"translation_domain",
|
||||
[None, "homeassistant"],
|
||||
ids=["own_domain", "shared_domain"],
|
||||
)
|
||||
async def test_show_progress_translation_domain(
|
||||
hass: HomeAssistant, manager: MockFlowManager, translation_domain: str | None
|
||||
) -> None:
|
||||
"""Test the progress action can be translated by another integration."""
|
||||
manager.hass = hass
|
||||
task = hass.async_create_task(asyncio.Event().wait())
|
||||
|
||||
@manager.mock_reg_handler("test")
|
||||
class TestFlow(data_entry_flow.FlowHandler):
|
||||
async def async_step_init(self, user_input=None):
|
||||
return self.async_show_progress(
|
||||
step_id="init",
|
||||
progress_action="task_one",
|
||||
progress_task=task,
|
||||
translation_domain=translation_domain,
|
||||
)
|
||||
|
||||
result = await manager.async_init("test")
|
||||
|
||||
assert result["type"] is data_entry_flow.FlowResultType.SHOW_PROGRESS
|
||||
assert result["progress_action"] == "task_one"
|
||||
assert result.get("translation_domain") == translation_domain
|
||||
|
||||
# Cancels the pending progress task
|
||||
manager.async_abort(result["flow_id"])
|
||||
|
||||
|
||||
async def test_show_progress_error(
|
||||
hass: HomeAssistant, manager: MockFlowManager
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user