Fix host override ignored in UniFi Protect public-only mode (#181176)

This commit is contained in:
Raphael Hehl
2026-09-03 19:48:20 +02:00
committed by GitHub
parent 2db9ed1e71
commit 3c46bcb85a
2 changed files with 58 additions and 2 deletions
@@ -134,6 +134,7 @@ def async_create_api_client(
public_api_session=async_create_clientsession(hass),
devices_ws_subscribed_models=DEVICES_WS_SUBSCRIBED_MODELS,
ignore_unadopted=False,
override_connection_host=entry.options.get(CONF_OVERRIDE_CHOST, False),
)
return _async_create_full_client(hass, entry)
+57 -2
View File
@@ -1,15 +1,31 @@
"""Test the UniFi Protect utils."""
import pytest
from homeassistant.components.unifiprotect.const import (
CONF_CONNECTION_MODE,
CONF_OVERRIDE_CHOST,
CONNECTION_MODE_API_KEY_ONLY,
DOMAIN,
)
from homeassistant.components.unifiprotect.utils import (
async_create_api_client,
async_create_session_client,
)
from homeassistant.const import (
CONF_API_KEY,
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.components.unifiprotect.utils import async_create_session_client
from homeassistant.const import CONF_PASSWORD
from homeassistant.core import HomeAssistant
from .utils import MockUFPFixture
from tests.common import MockConfigEntry
async def test_session_client_is_full_access_for_api_key_only_entry(
hass: HomeAssistant, ufp: MockUFPFixture
@@ -41,3 +57,42 @@ async def test_session_client_none_without_credentials(
)
assert async_create_session_client(hass, ufp.entry) is None
@pytest.mark.parametrize(
("connection_mode", "public_only"),
[
pytest.param({}, False, id="hybrid"),
pytest.param(
{CONF_CONNECTION_MODE: CONNECTION_MODE_API_KEY_ONLY}, True, id="public_only"
),
],
)
async def test_host_override_reaches_the_client(
hass: HomeAssistant, connection_mode: dict[str, str], public_only: bool
) -> None:
"""The host override option has to reach the client in both modes.
The library rewrites the host of the public RTSPS URLs only when the
client carries the flag, and a public-only entry has no other stream
source to fall back on.
"""
entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 443,
CONF_USERNAME: "test-username",
CONF_PASSWORD: "test-password",
CONF_API_KEY: "test-api-key",
CONF_VERIFY_SSL: False,
**connection_mode,
},
options={CONF_OVERRIDE_CHOST: True},
)
entry.add_to_hass(hass)
protect = async_create_api_client(hass, entry)
assert protect.is_public_only is public_only
assert protect.override_connection_host is True