From dfb94d891735de213c6abb23a404d40b3f037aa9 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Wed, 16 Oct 2024 13:33:47 +0200 Subject: [PATCH] Rename host to url in go2rtc config flow (#128508) --- homeassistant/components/go2rtc/__init__.py | 4 +-- .../components/go2rtc/config_flow.py | 16 ++++----- homeassistant/components/go2rtc/strings.json | 6 ++-- tests/components/go2rtc/conftest.py | 4 +-- tests/components/go2rtc/test_config_flow.py | 36 +++++++++---------- tests/components/go2rtc/test_init.py | 4 +-- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/go2rtc/__init__.py b/homeassistant/components/go2rtc/__init__.py index 6e1b8ab377126..27ec140076b05 100644 --- a/homeassistant/components/go2rtc/__init__.py +++ b/homeassistant/components/go2rtc/__init__.py @@ -8,7 +8,7 @@ async_register_webrtc_provider, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_URL from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -55,7 +55,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: entry.async_on_unload(server.stop) await server.start() - client = Go2RtcClient(async_get_clientsession(hass), entry.data[CONF_HOST]) + client = Go2RtcClient(async_get_clientsession(hass), entry.data[CONF_URL]) provider = WebRTCProvider(client) entry.async_on_unload(async_register_webrtc_provider(hass, provider)) diff --git a/homeassistant/components/go2rtc/config_flow.py b/homeassistant/components/go2rtc/config_flow.py index 5162850461402..0b1f37803461d 100644 --- a/homeassistant/components/go2rtc/config_flow.py +++ b/homeassistant/components/go2rtc/config_flow.py @@ -10,7 +10,7 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_URL from homeassistant.core import HomeAssistant from homeassistant.helpers import selector from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -55,28 +55,28 @@ async def async_step_user( if is_docker_env() and (binary := self._get_binary()): return self.async_create_entry( title=DOMAIN, - data={CONF_BINARY: binary, CONF_HOST: "http://localhost:1984/"}, + data={CONF_BINARY: binary, CONF_URL: "http://localhost:1984/"}, ) - return await self.async_step_host() + return await self.async_step_url() - async def async_step_host( + async def async_step_url( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Step to use selfhosted go2rtc server.""" errors = {} if user_input is not None: - if error := await _validate_url(self.hass, user_input[CONF_HOST]): - errors[CONF_HOST] = error + if error := await _validate_url(self.hass, user_input[CONF_URL]): + errors[CONF_URL] = error else: return self.async_create_entry(title=DOMAIN, data=user_input) return self.async_show_form( - step_id="host", + step_id="url", data_schema=self.add_suggested_values_to_schema( data_schema=vol.Schema( { - vol.Required(CONF_HOST): selector.TextSelector( + vol.Required(CONF_URL): selector.TextSelector( selector.TextSelectorConfig( type=selector.TextSelectorType.URL ) diff --git a/homeassistant/components/go2rtc/strings.json b/homeassistant/components/go2rtc/strings.json index 44e28d712c1b5..0258dcac69e38 100644 --- a/homeassistant/components/go2rtc/strings.json +++ b/homeassistant/components/go2rtc/strings.json @@ -1,12 +1,12 @@ { "config": { "step": { - "host": { + "url": { "data": { - "host": "[%key:common::config_flow::data::url%]" + "url": "[%key:common::config_flow::data::url%]" }, "data_description": { - "host": "The URL of your go2rtc instance." + "url": "The URL of your go2rtc instance." } } }, diff --git a/tests/components/go2rtc/conftest.py b/tests/components/go2rtc/conftest.py index 5d2d54815b4ae..b1c0f64121d60 100644 --- a/tests/components/go2rtc/conftest.py +++ b/tests/components/go2rtc/conftest.py @@ -8,7 +8,7 @@ from homeassistant.components.go2rtc.const import CONF_BINARY, DOMAIN from homeassistant.components.go2rtc.server import Server -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_URL from tests.common import MockConfigEntry @@ -56,5 +56,5 @@ def mock_config_entry() -> MockConfigEntry: return MockConfigEntry( domain=DOMAIN, title=DOMAIN, - data={CONF_HOST: "http://localhost:1984/", CONF_BINARY: "/usr/bin/go2rtc"}, + data={CONF_URL: "http://localhost:1984/", CONF_BINARY: "/usr/bin/go2rtc"}, ) diff --git a/tests/components/go2rtc/test_config_flow.py b/tests/components/go2rtc/test_config_flow.py index 25c993e7d3149..4af599810d7cf 100644 --- a/tests/components/go2rtc/test_config_flow.py +++ b/tests/components/go2rtc/test_config_flow.py @@ -6,7 +6,7 @@ from homeassistant.components.go2rtc.const import CONF_BINARY, DOMAIN from homeassistant.config_entries import SOURCE_USER -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_URL from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -53,7 +53,7 @@ async def test_docker_with_binary( assert result["title"] == "go2rtc" assert result["data"] == { CONF_BINARY: binary, - CONF_HOST: "http://localhost:1984/", + CONF_URL: "http://localhost:1984/", } @@ -66,12 +66,12 @@ async def test_docker_with_binary( (False, "/usr/bin/go2rtc"), ], ) -async def test_config_flow_host( +async def test_config_flow_url( hass: HomeAssistant, is_docker_env: bool, shutil_which: str | None, ) -> None: - """Test config flow with host input.""" + """Test config flow with url input.""" with ( patch( "homeassistant.components.go2rtc.config_flow.is_docker_env", @@ -87,18 +87,18 @@ async def test_config_flow_host( context={"source": SOURCE_USER}, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "host" - host = "http://go2rtc.local:1984/" + assert result["step_id"] == "url" + url = "http://go2rtc.local:1984/" result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: host}, + {CONF_URL: url}, ) assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "go2rtc" assert result["data"] == { - CONF_HOST: host, + CONF_URL: url, } @@ -119,38 +119,38 @@ async def test_flow_errors( context={"source": SOURCE_USER}, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "host" + assert result["step_id"] == "url" result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: "go2rtc.local:1984/"}, + {CONF_URL: "go2rtc.local:1984/"}, ) assert result["type"] is FlowResultType.FORM - assert result["errors"] == {"host": "invalid_url_schema"} + assert result["errors"] == {"url": "invalid_url_schema"} result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: "http://"}, + {CONF_URL: "http://"}, ) assert result["type"] is FlowResultType.FORM - assert result["errors"] == {"host": "invalid_url"} + assert result["errors"] == {"url": "invalid_url"} - host = "http://go2rtc.local:1984/" + url = "http://go2rtc.local:1984/" mock_client.streams.list.side_effect = Exception result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: host}, + {CONF_URL: url}, ) assert result["type"] is FlowResultType.FORM - assert result["errors"] == {"host": "cannot_connect"} + assert result["errors"] == {"url": "cannot_connect"} mock_client.streams.list.side_effect = None result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: host}, + {CONF_URL: url}, ) assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == "go2rtc" assert result["data"] == { - CONF_HOST: host, + CONF_URL: url, } diff --git a/tests/components/go2rtc/test_init.py b/tests/components/go2rtc/test_init.py index 95c0eb74c950f..f95e98825aef9 100644 --- a/tests/components/go2rtc/test_init.py +++ b/tests/components/go2rtc/test_init.py @@ -17,7 +17,7 @@ from homeassistant.components.go2rtc import WebRTCProvider from homeassistant.components.go2rtc.const import DOMAIN from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigFlow -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_URL from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -208,7 +208,7 @@ async def test_setup_go( config_entry = MockConfigEntry( domain=DOMAIN, title=DOMAIN, - data={CONF_HOST: "http://localhost:1984/"}, + data={CONF_URL: "http://localhost:1984/"}, ) def after_setup() -> None: