Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable media browser #262

Merged
merged 19 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions custom_components/frigate/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .api import FrigateApiClient, FrigateApiClientError
from .const import (
CONF_MEDIA_BROWSER_ENABLE,
CONF_NOTIFICATION_PROXY_ENABLE,
CONF_RTMP_URL_TEMPLATE,
DEFAULT_HOST,
Expand Down Expand Up @@ -147,6 +148,13 @@ async def async_step_init(
True,
),
): bool,
vol.Optional(
CONF_MEDIA_BROWSER_ENABLE,
default=self._config_entry.options.get(
CONF_MEDIA_BROWSER_ENABLE,
True,
),
): bool,
}

return cast(
Expand Down
1 change: 1 addition & 0 deletions custom_components/frigate/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

# Configuration and options
CONF_CAMERA_STATIC_IMAGE_HEIGHT = "camera_image_height"
CONF_MEDIA_BROWSER_ENABLE = "media_browser_enable"
CONF_NOTIFICATION_PROXY_ENABLE = "notification_proxy_enable"
CONF_PASSWORD = "password"
CONF_PATH = "path"
Expand Down
9 changes: 7 additions & 2 deletions custom_components/frigate/media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from . import get_friendly_name
from .api import FrigateApiClient, FrigateApiClientError
from .const import ATTR_CLIENT, DOMAIN, NAME
from .const import ATTR_CLIENT, CONF_MEDIA_BROWSER_ENABLE, DOMAIN, NAME
from .views import (
get_config_entry_for_frigate_instance_id,
get_default_config_entry,
Expand All @@ -47,7 +47,12 @@

async def async_get_media_source(hass: HomeAssistant) -> MediaSource:
"""Set up Frigate media source."""
return FrigateMediaSource(hass)
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
NickM-27 marked this conversation as resolved.
Show resolved Hide resolved

if config_entry.options.get(CONF_MEDIA_BROWSER_ENABLE, True):
return FrigateMediaSource(hass)

return None


class FrigateBrowseMediaMetadata:
Expand Down
3 changes: 2 additions & 1 deletion custom_components/frigate/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"init": {
"data": {
"rtmp_url_template": "RTMP URL template (see documentation)",
"notification_proxy_enable": "Enable the unauthenticated notification event proxy"
"notification_proxy_enable": "Enable the unauthenticated notification event proxy",
"media_browser_enable": "Enable the media browser"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from custom_components.frigate.api import FrigateApiClientError
from custom_components.frigate.const import (
CONF_MEDIA_BROWSER_ENABLE,
CONF_NOTIFICATION_PROXY_ENABLE,
CONF_RTMP_URL_TEMPLATE,
DOMAIN,
Expand Down Expand Up @@ -174,12 +175,14 @@ async def test_options_advanced(hass: HomeAssistant) -> None:
user_input={
CONF_RTMP_URL_TEMPLATE: "http://moo",
CONF_NOTIFICATION_PROXY_ENABLE: False,
CONF_MEDIA_BROWSER_ENABLE: False,
},
)
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"][CONF_RTMP_URL_TEMPLATE] == "http://moo"
assert not result["data"][CONF_NOTIFICATION_PROXY_ENABLE]
assert not result["data"][CONF_MEDIA_BROWSER_ENABLE]


async def test_options(hass: HomeAssistant) -> None:
Expand Down
33 changes: 32 additions & 1 deletion tests/test_media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
import pytest

from custom_components.frigate.api import FrigateApiClient, FrigateApiClientError
from custom_components.frigate.const import ATTR_CLIENT_ID, ATTR_MQTT, DOMAIN
from custom_components.frigate.const import (
ATTR_CLIENT_ID,
ATTR_MQTT,
CONF_MEDIA_BROWSER_ENABLE,
DOMAIN,
)
from custom_components.frigate.media_source import (
EventIdentifier,
EventSearchIdentifier,
FrigateMediaType,
Identifier,
RecordingIdentifier,
async_get_media_source,
)
from homeassistant.components import media_source
from homeassistant.components.media_player.errors import BrowseError
from homeassistant.components.media_source import const
from homeassistant.components.media_source.error import MediaSourceError, Unresolvable
from homeassistant.components.media_source.models import PlayMedia
Expand Down Expand Up @@ -79,6 +86,30 @@ def load_json(filename: str) -> Any:
yield client


async def test_async_disabled_browse_media(hass: HomeAssistant) -> None:
"""Test disabled browse media."""

# Create the default test Frigate instance.
create_mock_frigate_config_entry(
hass,
options={CONF_MEDIA_BROWSER_ENABLE: False},
)

loaded = False

try:
await async_get_media_source(hass)
await media_source.async_browse_media(
hass,
f"{const.URI_SCHEME}{DOMAIN}",
)
loaded = True
except BrowseError:
loaded = False

assert not loaded
NickM-27 marked this conversation as resolved.
Show resolved Hide resolved


async def test_async_browse_media_root(hass: HomeAssistant) -> None:
"""Test successful browse media root."""

Expand Down