Rename host to url in go2rtc config flow (#128508)

This commit is contained in:
Robert Resch 2024-10-16 13:33:47 +02:00 committed by GitHub
parent ed445d0ab8
commit dfb94d8917
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 35 deletions

View File

@ -8,7 +8,7 @@ from homeassistant.components.camera.webrtc import (
async_register_webrtc_provider, async_register_webrtc_provider,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession 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) entry.async_on_unload(server.stop)
await server.start() 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) provider = WebRTCProvider(client)
entry.async_on_unload(async_register_webrtc_provider(hass, provider)) entry.async_on_unload(async_register_webrtc_provider(hass, provider))

View File

@ -10,7 +10,7 @@ from go2rtc_client import Go2RtcClient
import voluptuous as vol import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult 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.core import HomeAssistant
from homeassistant.helpers import selector from homeassistant.helpers import selector
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -55,28 +55,28 @@ class Go2RTCConfigFlow(ConfigFlow, domain=DOMAIN):
if is_docker_env() and (binary := self._get_binary()): if is_docker_env() and (binary := self._get_binary()):
return self.async_create_entry( return self.async_create_entry(
title=DOMAIN, 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 self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Step to use selfhosted go2rtc server.""" """Step to use selfhosted go2rtc server."""
errors = {} errors = {}
if user_input is not None: if user_input is not None:
if error := await _validate_url(self.hass, user_input[CONF_HOST]): if error := await _validate_url(self.hass, user_input[CONF_URL]):
errors[CONF_HOST] = error errors[CONF_URL] = error
else: else:
return self.async_create_entry(title=DOMAIN, data=user_input) return self.async_create_entry(title=DOMAIN, data=user_input)
return self.async_show_form( return self.async_show_form(
step_id="host", step_id="url",
data_schema=self.add_suggested_values_to_schema( data_schema=self.add_suggested_values_to_schema(
data_schema=vol.Schema( data_schema=vol.Schema(
{ {
vol.Required(CONF_HOST): selector.TextSelector( vol.Required(CONF_URL): selector.TextSelector(
selector.TextSelectorConfig( selector.TextSelectorConfig(
type=selector.TextSelectorType.URL type=selector.TextSelectorType.URL
) )

View File

@ -1,12 +1,12 @@
{ {
"config": { "config": {
"step": { "step": {
"host": { "url": {
"data": { "data": {
"host": "[%key:common::config_flow::data::url%]" "url": "[%key:common::config_flow::data::url%]"
}, },
"data_description": { "data_description": {
"host": "The URL of your go2rtc instance." "url": "The URL of your go2rtc instance."
} }
} }
}, },

View File

@ -8,7 +8,7 @@ import pytest
from homeassistant.components.go2rtc.const import CONF_BINARY, DOMAIN from homeassistant.components.go2rtc.const import CONF_BINARY, DOMAIN
from homeassistant.components.go2rtc.server import Server from homeassistant.components.go2rtc.server import Server
from homeassistant.const import CONF_HOST from homeassistant.const import CONF_URL
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -56,5 +56,5 @@ def mock_config_entry() -> MockConfigEntry:
return MockConfigEntry( return MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
title=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"},
) )

View File

@ -6,7 +6,7 @@ import pytest
from homeassistant.components.go2rtc.const import CONF_BINARY, DOMAIN from homeassistant.components.go2rtc.const import CONF_BINARY, DOMAIN
from homeassistant.config_entries import SOURCE_USER 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.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
@ -53,7 +53,7 @@ async def test_docker_with_binary(
assert result["title"] == "go2rtc" assert result["title"] == "go2rtc"
assert result["data"] == { assert result["data"] == {
CONF_BINARY: binary, 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"), (False, "/usr/bin/go2rtc"),
], ],
) )
async def test_config_flow_host( async def test_config_flow_url(
hass: HomeAssistant, hass: HomeAssistant,
is_docker_env: bool, is_docker_env: bool,
shutil_which: str | None, shutil_which: str | None,
) -> None: ) -> None:
"""Test config flow with host input.""" """Test config flow with url input."""
with ( with (
patch( patch(
"homeassistant.components.go2rtc.config_flow.is_docker_env", "homeassistant.components.go2rtc.config_flow.is_docker_env",
@ -87,18 +87,18 @@ async def test_config_flow_host(
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
) )
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "host" assert result["step_id"] == "url"
host = "http://go2rtc.local:1984/" url = "http://go2rtc.local:1984/"
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: host}, {CONF_URL: url},
) )
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "go2rtc" assert result["title"] == "go2rtc"
assert result["data"] == { assert result["data"] == {
CONF_HOST: host, CONF_URL: url,
} }
@ -119,38 +119,38 @@ async def test_flow_errors(
context={"source": SOURCE_USER}, context={"source": SOURCE_USER},
) )
assert result["type"] is FlowResultType.FORM 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: "go2rtc.local:1984/"}, {CONF_URL: "go2rtc.local:1984/"},
) )
assert result["type"] is FlowResultType.FORM 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: "http://"}, {CONF_URL: "http://"},
) )
assert result["type"] is FlowResultType.FORM 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 mock_client.streams.list.side_effect = Exception
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: host}, {CONF_URL: url},
) )
assert result["type"] is FlowResultType.FORM 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 mock_client.streams.list.side_effect = None
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{CONF_HOST: host}, {CONF_URL: url},
) )
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "go2rtc" assert result["title"] == "go2rtc"
assert result["data"] == { assert result["data"] == {
CONF_HOST: host, CONF_URL: url,
} }

View File

@ -17,7 +17,7 @@ from homeassistant.components.camera.helper import get_camera_from_entity_id
from homeassistant.components.go2rtc import WebRTCProvider from homeassistant.components.go2rtc import WebRTCProvider
from homeassistant.components.go2rtc.const import DOMAIN from homeassistant.components.go2rtc.const import DOMAIN
from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigFlow 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.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
@ -208,7 +208,7 @@ async def test_setup_go(
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
title=DOMAIN, title=DOMAIN,
data={CONF_HOST: "http://localhost:1984/"}, data={CONF_URL: "http://localhost:1984/"},
) )
def after_setup() -> None: def after_setup() -> None: