diff --git a/homeassistant/components/go2rtc/__init__.py b/homeassistant/components/go2rtc/__init__.py index 2bcdaddf7391e99f82fad078469f26eab0ffac1b..9ffe9e25f78b1991c96b88859c1911080c0d6ee5 100644 --- a/homeassistant/components/go2rtc/__init__.py +++ b/homeassistant/components/go2rtc/__init__.py @@ -38,7 +38,7 @@ from homeassistant.helpers.typing import ConfigType from homeassistant.util.hass_dict import HassKey from homeassistant.util.package import is_docker_env -from .const import CONF_DEBUG_UI, DEBUG_UI_URL_MESSAGE, DEFAULT_URL, DOMAIN +from .const import CONF_DEBUG_UI, DEBUG_UI_URL_MESSAGE, DOMAIN, HA_MANAGED_URL from .server import Server _LOGGER = logging.getLogger(__name__) @@ -125,7 +125,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, on_stop) - url = DEFAULT_URL + url = HA_MANAGED_URL hass.data[_DATA_GO2RTC] = url discovery_flow.async_create_flow( diff --git a/homeassistant/components/go2rtc/const.py b/homeassistant/components/go2rtc/const.py index cb03e224e52501b3d43ca7dacd5457da63861530..d33ae3e389759f42d35af9c4984026097e55a1fe 100644 --- a/homeassistant/components/go2rtc/const.py +++ b/homeassistant/components/go2rtc/const.py @@ -4,4 +4,5 @@ DOMAIN = "go2rtc" CONF_DEBUG_UI = "debug_ui" DEBUG_UI_URL_MESSAGE = "Url and debug_ui cannot be set at the same time." -DEFAULT_URL = "http://localhost:1984/" +HA_MANAGED_API_PORT = 11984 +HA_MANAGED_URL = f"http://localhost:{HA_MANAGED_API_PORT}/" diff --git a/homeassistant/components/go2rtc/server.py b/homeassistant/components/go2rtc/server.py index eff067416b3fd83d2a15b1da52745ec52a3a2e90..6384cc5d49b3d2c03cf1bd18ab5096c25113550e 100644 --- a/homeassistant/components/go2rtc/server.py +++ b/homeassistant/components/go2rtc/server.py @@ -11,7 +11,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession -from .const import DEFAULT_URL +from .const import HA_MANAGED_API_PORT, HA_MANAGED_URL _LOGGER = logging.getLogger(__name__) _TERMINATE_TIMEOUT = 5 @@ -26,13 +26,14 @@ _RESPAWN_COOLDOWN = 1 # - Clear default ice servers _GO2RTC_CONFIG_FORMAT = r""" api: - listen: "{api_ip}:1984" + listen: "{api_ip}:{api_port}" rtsp: # ffmpeg needs rtsp for opus audio transcoding - listen: "127.0.0.1:8554" + listen: "127.0.0.1:18554" webrtc: + listen: ":18555/tcp" ice_servers: [] """ @@ -52,7 +53,11 @@ def _create_temp_file(api_ip: str) -> str: # Set delete=False to prevent the file from being deleted when the file is closed # Linux is clearing tmp folder on reboot, so no need to delete it manually with NamedTemporaryFile(prefix="go2rtc_", suffix=".yaml", delete=False) as file: - file.write(_GO2RTC_CONFIG_FORMAT.format(api_ip=api_ip).encode()) + file.write( + _GO2RTC_CONFIG_FORMAT.format( + api_ip=api_ip, api_port=HA_MANAGED_API_PORT + ).encode() + ) return file.name @@ -113,7 +118,7 @@ class Server: raise Go2RTCServerStartError from err # Check the server version - client = Go2RtcRestClient(async_get_clientsession(self._hass), DEFAULT_URL) + client = Go2RtcRestClient(async_get_clientsession(self._hass), HA_MANAGED_URL) await client.validate_server_version() async def _log_output(self, process: asyncio.subprocess.Process) -> None: @@ -173,7 +178,7 @@ class Server: async def _monitor_api(self) -> None: """Raise if the go2rtc process terminates.""" - client = Go2RtcRestClient(async_get_clientsession(self._hass), DEFAULT_URL) + client = Go2RtcRestClient(async_get_clientsession(self._hass), HA_MANAGED_URL) _LOGGER.debug("Monitoring go2rtc API") try: diff --git a/tests/components/go2rtc/test_server.py b/tests/components/go2rtc/test_server.py index fedf155baf5613657cab512e6c0897aa02d4b114..5b430d66641873e9fc8f337c9f8bd585261efa1d 100644 --- a/tests/components/go2rtc/test_server.py +++ b/tests/components/go2rtc/test_server.py @@ -71,13 +71,14 @@ async def test_server_run_success( mock_tempfile.write.assert_called_once_with( f""" api: - listen: "{api_ip}:1984" + listen: "{api_ip}:11984" rtsp: # ffmpeg needs rtsp for opus audio transcoding - listen: "127.0.0.1:8554" + listen: "127.0.0.1:18554" webrtc: + listen: ":18555/tcp" ice_servers: [] """.encode() )