Skip to content

Commit 126fd21

Browse files
authored
Bump go2rtc to 1.9.12 and go2rtc-client to 0.3.0 (home-assistant#156948)
1 parent 0327b0e commit 126fd21

File tree

13 files changed

+134
-68
lines changed

13 files changed

+134
-68
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

homeassistant/components/go2rtc/__init__.py

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,6 @@
6060
_LOGGER = logging.getLogger(__name__)
6161

6262
_FFMPEG = "ffmpeg"
63-
_SUPPORTED_STREAMS = frozenset(
64-
(
65-
"bubble",
66-
"dvrip",
67-
"expr",
68-
_FFMPEG,
69-
"gopro",
70-
"homekit",
71-
"http",
72-
"https",
73-
"httpx",
74-
"isapi",
75-
"ivideon",
76-
"kasa",
77-
"nest",
78-
"onvif",
79-
"roborock",
80-
"rtmp",
81-
"rtmps",
82-
"rtmpx",
83-
"rtsp",
84-
"rtsps",
85-
"rtspx",
86-
"tapo",
87-
"tcp",
88-
"webrtc",
89-
"webtorrent",
90-
)
91-
)
9263

9364
CONFIG_SCHEMA = vol.Schema(
9465
{
@@ -197,6 +168,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: Go2RtcConfigEntry) -> bo
197168
return False
198169

199170
provider = entry.runtime_data = WebRTCProvider(hass, url, session, client)
171+
await provider.initialize()
200172
entry.async_on_unload(async_register_webrtc_provider(hass, provider))
201173
return True
202174

@@ -228,16 +200,21 @@ def __init__(
228200
self._session = session
229201
self._rest_client = rest_client
230202
self._sessions: dict[str, Go2RtcWsClient] = {}
203+
self._supported_schemes: set[str] = set()
231204

232205
@property
233206
def domain(self) -> str:
234207
"""Return the integration domain of the provider."""
235208
return DOMAIN
236209

210+
async def initialize(self) -> None:
211+
"""Initialize the provider."""
212+
self._supported_schemes = await self._rest_client.schemes.list()
213+
237214
@callback
238215
def async_is_supported(self, stream_source: str) -> bool:
239216
"""Return if this provider is supports the Camera as source."""
240-
return stream_source.partition(":")[0] in _SUPPORTED_STREAMS
217+
return stream_source.partition(":")[0] in self._supported_schemes
241218

242219
async def async_handle_async_webrtc_offer(
243220
self,

homeassistant/components/go2rtc/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
DEBUG_UI_URL_MESSAGE = "Url and debug_ui cannot be set at the same time."
77
HA_MANAGED_API_PORT = 11984
88
HA_MANAGED_URL = f"http://localhost:{HA_MANAGED_API_PORT}/"
9-
RECOMMENDED_VERSION = "1.9.11"
9+
RECOMMENDED_VERSION = "1.9.12"

homeassistant/components/go2rtc/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"integration_type": "system",
99
"iot_class": "local_polling",
1010
"quality_scale": "internal",
11-
"requirements": ["go2rtc-client==0.2.1"],
11+
"requirements": ["go2rtc-client==0.3.0"],
1212
"single_config_entry": true
1313
}

homeassistant/components/go2rtc/server.py

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@
2929
_GO2RTC_CONFIG_FORMAT = r"""# This file is managed by Home Assistant
3030
# Do not edit it manually
3131
32+
app:
33+
modules: {app_modules}
34+
3235
api:
3336
listen: "{api_ip}:{api_port}"
37+
allow_paths: {api_allow_paths}
38+
39+
# ffmpeg needs the exec module
40+
# Restrict execution to only ffmpeg binary
41+
exec:
42+
allow_paths:
43+
- ffmpeg
3444
3545
rtsp:
3646
listen: "127.0.0.1:18554"
@@ -40,6 +50,43 @@
4050
ice_servers: []
4151
"""
4252

53+
_APP_MODULES = (
54+
"api",
55+
"exec", # Execution module for ffmpeg
56+
"ffmpeg",
57+
"http",
58+
"mjpeg",
59+
"onvif",
60+
"rtmp",
61+
"rtsp",
62+
"srtp",
63+
"webrtc",
64+
"ws",
65+
)
66+
67+
_API_ALLOW_PATHS = (
68+
"/", # UI static page and version control
69+
"/api", # Main API path
70+
"/api/frame.jpeg", # Snapshot functionality
71+
"/api/schemes", # Supported stream schemes
72+
"/api/streams", # Stream management
73+
"/api/webrtc", # Webrtc functionality
74+
"/api/ws", # Websocket functionality (e.g. webrtc candidates)
75+
)
76+
77+
# Additional modules when UI is enabled
78+
_UI_APP_MODULES = (
79+
*_APP_MODULES,
80+
"debug",
81+
)
82+
# Additional api paths when UI is enabled
83+
_UI_API_ALLOW_PATHS = (
84+
*_API_ALLOW_PATHS,
85+
"/api/config", # UI config view
86+
"/api/log", # UI log view
87+
"/api/streams.dot", # UI network view
88+
)
89+
4390
_LOG_LEVEL_MAP = {
4491
"TRC": logging.DEBUG,
4592
"DBG": logging.DEBUG,
@@ -61,14 +108,34 @@ class Go2RTCWatchdogError(HomeAssistantError):
61108
"""Raised on watchdog error."""
62109

63110

64-
def _create_temp_file(api_ip: str) -> str:
111+
def _format_list_for_yaml(items: tuple[str, ...]) -> str:
112+
"""Format a list of strings for yaml config."""
113+
if not items:
114+
return "[]"
115+
formatted_items = ",".join(f'"{item}"' for item in items)
116+
return f"[{formatted_items}]"
117+
118+
119+
def _create_temp_file(enable_ui: bool) -> str:
65120
"""Create temporary config file."""
121+
app_modules: tuple[str, ...] = _APP_MODULES
122+
api_paths: tuple[str, ...] = _API_ALLOW_PATHS
123+
api_ip = _LOCALHOST_IP
124+
if enable_ui:
125+
app_modules = _UI_APP_MODULES
126+
api_paths = _UI_API_ALLOW_PATHS
127+
# Listen on all interfaces for allowing access from all ips
128+
api_ip = ""
129+
66130
# Set delete=False to prevent the file from being deleted when the file is closed
67131
# Linux is clearing tmp folder on reboot, so no need to delete it manually
68132
with NamedTemporaryFile(prefix="go2rtc_", suffix=".yaml", delete=False) as file:
69133
file.write(
70134
_GO2RTC_CONFIG_FORMAT.format(
71-
api_ip=api_ip, api_port=HA_MANAGED_API_PORT
135+
api_ip=api_ip,
136+
api_port=HA_MANAGED_API_PORT,
137+
app_modules=_format_list_for_yaml(app_modules),
138+
api_allow_paths=_format_list_for_yaml(api_paths),
72139
).encode()
73140
)
74141
return file.name
@@ -86,10 +153,7 @@ def __init__(
86153
self._log_buffer: deque[str] = deque(maxlen=_LOG_BUFFER_SIZE)
87154
self._process: asyncio.subprocess.Process | None = None
88155
self._startup_complete = asyncio.Event()
89-
self._api_ip = _LOCALHOST_IP
90-
if enable_ui:
91-
# Listen on all interfaces for allowing access from all ips
92-
self._api_ip = ""
156+
self._enable_ui = enable_ui
93157
self._watchdog_task: asyncio.Task | None = None
94158
self._watchdog_tasks: list[asyncio.Task] = []
95159

@@ -104,7 +168,7 @@ async def _start(self) -> None:
104168
"""Start the server."""
105169
_LOGGER.debug("Starting go2rtc server")
106170
config_file = await self._hass.async_add_executor_job(
107-
_create_temp_file, self._api_ip
171+
_create_temp_file, self._enable_ui
108172
)
109173

110174
self._startup_complete.clear()

homeassistant/package_constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cryptography==46.0.2
3333
dbus-fast==3.0.0
3434
file-read-backwards==2.0.0
3535
fnv-hash-fast==1.6.0
36-
go2rtc-client==0.2.1
36+
go2rtc-client==0.3.0
3737
ha-ffmpeg==3.2.2
3838
habluetooth==5.7.0
3939
hass-nabucasa==1.5.1

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements_test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
astroid==4.0.1
1111
coverage==7.10.6
1212
freezegun==1.5.2
13-
go2rtc-client==0.2.1
13+
go2rtc-client==0.3.0
1414
# librt is an internal mypy dependency
1515
librt==0.2.1
1616
license-expression==30.4.3

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/hassfest/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)