From 86dbe068e702726b4403f6a4ec36cde1c1a5cdd3 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Thu, 20 Jan 2022 01:14:13 -0800 Subject: [PATCH] Abort rtsp_to_webrtc config flow on error during add-on discovery (#64500) --- homeassistant/components/rtsp_to_webrtc/config_flow.py | 2 +- homeassistant/components/rtsp_to_webrtc/strings.json | 4 +++- tests/components/rtsp_to_webrtc/test_config_flow.py | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/rtsp_to_webrtc/config_flow.py b/homeassistant/components/rtsp_to_webrtc/config_flow.py index 8594d1faae6..32735f3e824 100644 --- a/homeassistant/components/rtsp_to_webrtc/config_flow.py +++ b/homeassistant/components/rtsp_to_webrtc/config_flow.py @@ -90,7 +90,7 @@ class RTSPToWebRTCConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): port = self._hassio_discovery[CONF_PORT] url = f"http://{host}:{port}" if error_code := await self._test_connection(url): - errors = {"base": error_code} + return self.async_abort(reason=error_code) if user_input is None or errors: # Show initial confirmation or errors from server validation diff --git a/homeassistant/components/rtsp_to_webrtc/strings.json b/homeassistant/components/rtsp_to_webrtc/strings.json index b6bbce17a9a..5ef91eaf206 100644 --- a/homeassistant/components/rtsp_to_webrtc/strings.json +++ b/homeassistant/components/rtsp_to_webrtc/strings.json @@ -19,7 +19,9 @@ "server_unreachable": "Unable to communicate with RTSPtoWebRTC server. Check logs for more information." }, "abort": { - "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" + "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]", + "server_failure": "RTSPtoWebRTC server returned an error. Check logs for more information.", + "server_unreachable": "Unable to communicate with RTSPtoWebRTC server. Check logs for more information." } } } diff --git a/tests/components/rtsp_to_webrtc/test_config_flow.py b/tests/components/rtsp_to_webrtc/test_config_flow.py index ad0cd0006ba..a6cd4d6798f 100644 --- a/tests/components/rtsp_to_webrtc/test_config_flow.py +++ b/tests/components/rtsp_to_webrtc/test_config_flow.py @@ -210,6 +210,5 @@ async def test_hassio_discovery_server_failure(hass: HomeAssistant) -> None: side_effect=rtsp_to_webrtc.exceptions.ResponseError(), ): result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) - assert result.get("type") == "form" - assert result.get("step_id") == "hassio_confirm" - assert result.get("errors") == {"base": "server_failure"} + assert result.get("type") == "abort" + assert result.get("reason") == "server_failure"