From 62ae2a3bd5fe40f8622bc53812b2570d82d74cf3 Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Sat, 5 Oct 2024 03:05:11 -0700 Subject: [PATCH] Update Radarr config flow to standardize ports (#127620) --- homeassistant/components/radarr/config_flow.py | 7 +++++++ tests/components/radarr/test_config_flow.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/homeassistant/components/radarr/config_flow.py b/homeassistant/components/radarr/config_flow.py index c748c63e992..ab32a5d7352 100644 --- a/homeassistant/components/radarr/config_flow.py +++ b/homeassistant/components/radarr/config_flow.py @@ -10,6 +10,7 @@ from aiopyarr import exceptions from aiopyarr.models.host_configuration import PyArrHostConfiguration from aiopyarr.radarr_client import RadarrClient import voluptuous as vol +from yarl import URL from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL @@ -54,6 +55,12 @@ class RadarrConfigFlow(ConfigFlow, domain=DOMAIN): user_input = dict(self.entry.data) if self.entry else None else: + # aiopyarr defaults to the service port if one isn't given + # this is counter to standard practice where http = 80 + # and https = 443. + url = URL(user_input[CONF_URL]) + user_input[CONF_URL] = f"{url.scheme}://{url.host}:{url.port}{url.path}" + try: if result := await validate_input(self.hass, user_input): user_input[CONF_API_KEY] = result[1] diff --git a/tests/components/radarr/test_config_flow.py b/tests/components/radarr/test_config_flow.py index 0ff93536957..096c78e1c4a 100644 --- a/tests/components/radarr/test_config_flow.py +++ b/tests/components/radarr/test_config_flow.py @@ -137,6 +137,23 @@ async def test_zero_conf(hass: HomeAssistant) -> None: assert result["data"] == CONF_DATA +async def test_url_rewrite(hass: HomeAssistant) -> None: + """Test auth flow url rewrite.""" + with patch( + "homeassistant.components.radarr.config_flow.RadarrClient.async_try_zeroconf", + return_value=("v3", API_KEY, "/test"), + ): + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={CONF_SOURCE: SOURCE_USER}, + data={CONF_URL: "https://192.168.1.100/test", CONF_VERIFY_SSL: False}, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == DEFAULT_NAME + assert result["data"][CONF_URL] == "https://192.168.1.100:443/test" + + @pytest.mark.freeze_time("2021-12-03 00:00:00+00:00") async def test_full_reauth_flow_implementation( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker