diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 2268d1ca7e8b..d75c99151a79 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -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: diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index e9a4c80c444f..d655369587e1 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -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 diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 2462a6eed149..424232d85c3f 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -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: