From 2d5cb93ced0c8b03852cada4fa142d20bec1b4ae Mon Sep 17 00:00:00 2001 From: Bilal Atique <74999164+BilalAtique@users.noreply.github.com> Date: Tue, 29 Sep 2026 11:37:02 +0500 Subject: [PATCH] Add repair issue for unsupported go2rtc server version (#183171) --- homeassistant/components/go2rtc/__init__.py | 12 ++++++ homeassistant/components/go2rtc/strings.json | 4 ++ tests/components/go2rtc/test_init.py | 45 +++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/go2rtc/__init__.py b/homeassistant/components/go2rtc/__init__.py index 8ab40c0fd2a2..a002326ddc85 100644 --- a/homeassistant/components/go2rtc/__init__.py +++ b/homeassistant/components/go2rtc/__init__.py @@ -238,6 +238,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: Go2RtcConfigEntry) -> bo _LOGGER.warning("Could not connect to go2rtc instance on %s (%s)", url, err) return False except Go2RtcVersionError as err: + ir.async_create_issue( + hass, + DOMAIN, + "unsupported_version", + is_fixable=False, + is_persistent=False, + severity=ir.IssueSeverity.ERROR, + translation_key="unsupported_version", + translation_placeholders={"error": str(err)}, + ) raise ConfigEntryNotReady( f"The go2rtc server version is not supported, {err}" ) from err @@ -245,6 +255,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: Go2RtcConfigEntry) -> bo _LOGGER.warning("Could not connect to go2rtc instance on %s (%s)", url, err) return False + ir.async_delete_issue(hass, DOMAIN, "unsupported_version") + provider = entry.runtime_data = WebRTCProvider(hass, url, session, client) await provider.initialize() entry.async_on_unload(async_register_webrtc_provider(hass, provider)) diff --git a/homeassistant/components/go2rtc/strings.json b/homeassistant/components/go2rtc/strings.json index ce60f5d26c4f..9c883d8d75db 100644 --- a/homeassistant/components/go2rtc/strings.json +++ b/homeassistant/components/go2rtc/strings.json @@ -3,6 +3,10 @@ "recommended_version": { "description": "We detected that you are using an outdated go2rtc server version. For the best experience, we recommend updating the go2rtc server to version `{recommended_version}`.\nCurrently you are using version `{current_version}`.", "title": "Outdated go2rtc server detected" + }, + "unsupported_version": { + "description": "The go2rtc server runs a version that Home Assistant does not support: {error}.\nWebRTC streaming through go2rtc is unavailable until you update the go2rtc server to a supported version. Home Assistant retries automatically and removes this message when the connection succeeds.", + "title": "Unsupported go2rtc server version" } } } diff --git a/tests/components/go2rtc/test_init.py b/tests/components/go2rtc/test_init.py index e24c3770b977..fba703cb15fd 100644 --- a/tests/components/go2rtc/test_init.py +++ b/tests/components/go2rtc/test_init.py @@ -2,6 +2,7 @@ import asyncio from collections.abc import Awaitable, Callable +from datetime import timedelta import logging from pathlib import Path from typing import NamedTuple @@ -10,6 +11,7 @@ from unittest.mock import ANY, AsyncMock, Mock, patch from aiohttp import UnixConnector, encode_basic_auth from aiohttp.client_exceptions import ClientConnectionError, ServerConnectionError from awesomeversion import AwesomeVersion +from freezegun.api import FrozenDateTimeFactory from go2rtc_client import Stream from go2rtc_client.exceptions import Go2RtcClientError, Go2RtcVersionError from go2rtc_client.models import Producer @@ -58,7 +60,7 @@ from homeassistant.setup import async_setup_component from . import MockCamera -from tests.common import MockConfigEntry, load_fixture_bytes +from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture_bytes # The go2rtc provider does not inspect the details of the offer and answer, # and is only a pass through. @@ -979,6 +981,47 @@ async def test_setup_with_recommended_version_repair( } +@pytest.mark.parametrize("config", [{DOMAIN: {CONF_URL: "http://localhost:1984"}}]) +@pytest.mark.usefixtures("server") +async def test_setup_with_unsupported_version_repair( + hass: HomeAssistant, + issue_registry: ir.IssueRegistry, + rest_client: AsyncMock, + config: ConfigType, + freezer: FrozenDateTimeFactory, +) -> None: + """Test a repair issue is shown while the server version is unsupported.""" + rest_client.validate_server_version.side_effect = Go2RtcVersionError( + "1.9.2", "1.9.13", "2.0.0" + ) + assert await async_setup_component(hass, DOMAIN, config) + await hass.async_block_till_done(wait_background_tasks=True) + + config_entry = hass.config_entries.async_entries(DOMAIN)[0] + assert config_entry.state is ConfigEntryState.SETUP_RETRY + issue = issue_registry.async_get_issue(DOMAIN, "unsupported_version") + assert issue + assert issue.is_fixable is False + assert issue.is_persistent is False + assert issue.severity == ir.IssueSeverity.ERROR + assert issue.translation_key == "unsupported_version" + assert issue.translation_placeholders == { + "error": "server version '1.9.2' not >= 1.9.13 and < 2.0.0", + } + + # The retry after the server is updated clears the issue + rest_client.validate_server_version.side_effect = None + rest_client.validate_server_version.return_value = AwesomeVersion( + RECOMMENDED_VERSION + ) + freezer.tick(timedelta(seconds=11)) + async_fire_time_changed(hass) + await hass.async_block_till_done(wait_background_tasks=True) + + assert config_entry.state is ConfigEntryState.LOADED + assert issue_registry.async_get_issue(DOMAIN, "unsupported_version") is None + + @pytest.mark.usefixtures("init_integration") async def test_async_get_image( hass: HomeAssistant,