mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Append a 1 to all go2rtc ports to avoid port conflicts (#129881)
This commit is contained in:
parent
79901cede9
commit
eafed2b86c
@ -38,7 +38,7 @@ from homeassistant.helpers.typing import ConfigType
|
|||||||
from homeassistant.util.hass_dict import HassKey
|
from homeassistant.util.hass_dict import HassKey
|
||||||
from homeassistant.util.package import is_docker_env
|
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
|
from .server import Server
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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)
|
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, on_stop)
|
||||||
|
|
||||||
url = DEFAULT_URL
|
url = HA_MANAGED_URL
|
||||||
|
|
||||||
hass.data[_DATA_GO2RTC] = url
|
hass.data[_DATA_GO2RTC] = url
|
||||||
discovery_flow.async_create_flow(
|
discovery_flow.async_create_flow(
|
||||||
|
@ -4,4 +4,5 @@ DOMAIN = "go2rtc"
|
|||||||
|
|
||||||
CONF_DEBUG_UI = "debug_ui"
|
CONF_DEBUG_UI = "debug_ui"
|
||||||
DEBUG_UI_URL_MESSAGE = "Url and debug_ui cannot be set at the same time."
|
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}/"
|
||||||
|
@ -11,7 +11,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_TERMINATE_TIMEOUT = 5
|
_TERMINATE_TIMEOUT = 5
|
||||||
@ -26,13 +26,14 @@ _RESPAWN_COOLDOWN = 1
|
|||||||
# - Clear default ice servers
|
# - Clear default ice servers
|
||||||
_GO2RTC_CONFIG_FORMAT = r"""
|
_GO2RTC_CONFIG_FORMAT = r"""
|
||||||
api:
|
api:
|
||||||
listen: "{api_ip}:1984"
|
listen: "{api_ip}:{api_port}"
|
||||||
|
|
||||||
rtsp:
|
rtsp:
|
||||||
# ffmpeg needs rtsp for opus audio transcoding
|
# ffmpeg needs rtsp for opus audio transcoding
|
||||||
listen: "127.0.0.1:8554"
|
listen: "127.0.0.1:18554"
|
||||||
|
|
||||||
webrtc:
|
webrtc:
|
||||||
|
listen: ":18555/tcp"
|
||||||
ice_servers: []
|
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
|
# 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
|
# Linux is clearing tmp folder on reboot, so no need to delete it manually
|
||||||
with NamedTemporaryFile(prefix="go2rtc_", suffix=".yaml", delete=False) as file:
|
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
|
return file.name
|
||||||
|
|
||||||
|
|
||||||
@ -113,7 +118,7 @@ class Server:
|
|||||||
raise Go2RTCServerStartError from err
|
raise Go2RTCServerStartError from err
|
||||||
|
|
||||||
# Check the server version
|
# 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()
|
await client.validate_server_version()
|
||||||
|
|
||||||
async def _log_output(self, process: asyncio.subprocess.Process) -> None:
|
async def _log_output(self, process: asyncio.subprocess.Process) -> None:
|
||||||
@ -173,7 +178,7 @@ class Server:
|
|||||||
|
|
||||||
async def _monitor_api(self) -> None:
|
async def _monitor_api(self) -> None:
|
||||||
"""Raise if the go2rtc process terminates."""
|
"""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")
|
_LOGGER.debug("Monitoring go2rtc API")
|
||||||
try:
|
try:
|
||||||
|
@ -71,13 +71,14 @@ async def test_server_run_success(
|
|||||||
mock_tempfile.write.assert_called_once_with(
|
mock_tempfile.write.assert_called_once_with(
|
||||||
f"""
|
f"""
|
||||||
api:
|
api:
|
||||||
listen: "{api_ip}:1984"
|
listen: "{api_ip}:11984"
|
||||||
|
|
||||||
rtsp:
|
rtsp:
|
||||||
# ffmpeg needs rtsp for opus audio transcoding
|
# ffmpeg needs rtsp for opus audio transcoding
|
||||||
listen: "127.0.0.1:8554"
|
listen: "127.0.0.1:18554"
|
||||||
|
|
||||||
webrtc:
|
webrtc:
|
||||||
|
listen: ":18555/tcp"
|
||||||
ice_servers: []
|
ice_servers: []
|
||||||
""".encode()
|
""".encode()
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user