From 4f1e4e74713423588a009e4d28c5e67858be07d9 Mon Sep 17 00:00:00 2001
From: Erik Montnemery <erik@montnemery.com>
Date: Fri, 25 Oct 2024 16:10:14 +0200
Subject: [PATCH] Include go2rtc in default_config (#129144)

* Include go2rtc in default_config

* Fail if binary not found in docker environment
---
 .../components/default_config/manifest.json   |  1 +
 homeassistant/components/go2rtc/__init__.py   |  6 +++++-
 homeassistant/package_constraints.txt         |  1 +
 tests/components/go2rtc/test_init.py          | 21 +++++++++++++++++--
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/homeassistant/components/default_config/manifest.json b/homeassistant/components/default_config/manifest.json
index addf49b9542..8299fe43f09 100644
--- a/homeassistant/components/default_config/manifest.json
+++ b/homeassistant/components/default_config/manifest.json
@@ -9,6 +9,7 @@
     "conversation",
     "dhcp",
     "energy",
+    "go2rtc",
     "history",
     "homeassistant_alerts",
     "logbook",
diff --git a/homeassistant/components/go2rtc/__init__.py b/homeassistant/components/go2rtc/__init__.py
index 5f57d801875..9421069fd7f 100644
--- a/homeassistant/components/go2rtc/__init__.py
+++ b/homeassistant/components/go2rtc/__init__.py
@@ -62,8 +62,12 @@ CONFIG_SCHEMA = vol.Schema(
 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
     """Set up WebRTC."""
     url: str | None = None
-    if not (url := config[DOMAIN].get(CONF_URL)):
+    if not (configured_by_user := DOMAIN in config) or not (
+        url := config[DOMAIN].get(CONF_URL)
+    ):
         if not is_docker_env():
+            if not configured_by_user:
+                return True
             _LOGGER.warning("Go2rtc URL required in non-docker installs")
             return False
         if not (binary := await _get_binary(hass)):
diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt
index 3449459281a..1863181e1f0 100644
--- a/homeassistant/package_constraints.txt
+++ b/homeassistant/package_constraints.txt
@@ -26,6 +26,7 @@ ciso8601==2.3.1
 cryptography==43.0.1
 dbus-fast==2.24.3
 fnv-hash-fast==1.0.2
+go2rtc-client==0.0.1b0
 ha-av==10.1.1
 ha-ffmpeg==3.2.1
 habluetooth==3.6.0
diff --git a/tests/components/go2rtc/test_init.py b/tests/components/go2rtc/test_init.py
index 690bd83b37c..0df38f3cd37 100644
--- a/tests/components/go2rtc/test_init.py
+++ b/tests/components/go2rtc/test_init.py
@@ -259,11 +259,28 @@ ERR_INVALID_URL = "Invalid config for 'go2rtc': invalid url"
 ERR_URL_REQUIRED = "Go2rtc URL required in non-docker installs"
 
 
+@pytest.mark.parametrize(
+    ("config", "go2rtc_binary", "is_docker_env"),
+    [
+        ({}, None, False),
+    ],
+)
+@pytest.mark.usefixtures("mock_get_binary", "mock_is_docker_env", "mock_server")
+async def test_non_user_setup_with_error(
+    hass: HomeAssistant,
+    config: ConfigType,
+    caplog: pytest.LogCaptureFixture,
+) -> None:
+    """Test setup integration does not fail if not setup by user."""
+
+    assert await async_setup_component(hass, DOMAIN, config)
+
+
 @pytest.mark.parametrize(
     ("config", "go2rtc_binary", "is_docker_env", "expected_log_message"),
     [
-        ({}, None, False, "KeyError: 'go2rtc'"),
-        ({}, None, True, "KeyError: 'go2rtc'"),
+        ({}, None, True, ERR_BINARY_NOT_FOUND),
+        ({}, "/usr/bin/go2rtc", True, ERR_CONNECT),
         ({DOMAIN: {}}, None, False, ERR_URL_REQUIRED),
         ({DOMAIN: {}}, None, True, ERR_BINARY_NOT_FOUND),
         ({DOMAIN: {}}, "/usr/bin/go2rtc", True, ERR_CONNECT),
-- 
GitLab