diff --git a/homeassistant/components/generic/config_flow.py b/homeassistant/components/generic/config_flow.py index 7b10cdfb64b..a8f3f6f386b 100644 --- a/homeassistant/components/generic/config_flow.py +++ b/homeassistant/components/generic/config_flow.py @@ -282,7 +282,7 @@ async def async_test_stream( return {CONF_STREAM_SOURCE: "timeout"} await stream.stop() except StreamWorkerError as err: - return {CONF_STREAM_SOURCE: str(err)} + return {CONF_STREAM_SOURCE: "unknown_with_details", "error_details": str(err)} except PermissionError: return {CONF_STREAM_SOURCE: "stream_not_permitted"} except OSError as err: @@ -339,6 +339,7 @@ class GenericIPCamConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Handle the start of the config flow.""" errors = {} + description_placeholders = {} hass = self.hass if user_input: # Secondary validation because serialised vol can't seem to handle this complexity: @@ -372,6 +373,8 @@ class GenericIPCamConfigFlow(ConfigFlow, domain=DOMAIN): # temporary preview for user to check the image self.preview_cam = user_input return await self.async_step_user_confirm_still() + if "error_details" in errors: + description_placeholders["error"] = errors.pop("error_details") elif self.user_input: user_input = self.user_input else: @@ -379,6 +382,7 @@ class GenericIPCamConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="user", data_schema=build_schema(user_input), + description_placeholders=description_placeholders, errors=errors, ) diff --git a/homeassistant/components/generic/strings.json b/homeassistant/components/generic/strings.json index b05f17efc8d..94360a5b7c2 100644 --- a/homeassistant/components/generic/strings.json +++ b/homeassistant/components/generic/strings.json @@ -3,6 +3,7 @@ "config": { "error": { "unknown": "[%key:common::config_flow::error::unknown%]", + "unknown_with_details": "An unknown error occurred: {error}", "already_exists": "A camera with these URL settings already exists.", "unable_still_load": "Unable to load valid image from still image URL (e.g. invalid host, URL or authentication failure). Review log for more info.", "unable_still_load_auth": "Unable to load valid image from still image URL: The camera may require a user name and password, or they are not correct.", diff --git a/tests/components/generic/test_config_flow.py b/tests/components/generic/test_config_flow.py index 7575a078675..a882ca4cd8d 100644 --- a/tests/components/generic/test_config_flow.py +++ b/tests/components/generic/test_config_flow.py @@ -637,10 +637,6 @@ async def test_form_stream_other_error(hass: HomeAssistant, user_flow) -> None: await hass.async_block_till_done() -@pytest.mark.parametrize( # Remove when translations fixed - "ignore_translations", - ["component.generic.config.error.Some message"], -) @respx.mock @pytest.mark.usefixtures("fakeimg_png") async def test_form_stream_worker_error( @@ -656,7 +652,8 @@ async def test_form_stream_worker_error( TESTDATA, ) assert result2["type"] is FlowResultType.FORM - assert result2["errors"] == {"stream_source": "Some message"} + assert result2["errors"] == {"stream_source": "unknown_with_details"} + assert result2["description_placeholders"] == {"error": "Some message"} @respx.mock