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

Replace MEDIA_CLASS_ and MEDIA_TYPE_ with MediaClass and MediaType #726

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions custom_components/frigate/media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

from homeassistant.components.media_player.const import (
MEDIA_CLASS_DIRECTORY,
MEDIA_CLASS_IMAGE,
MEDIA_CLASS_MOVIE,
MEDIA_CLASS_VIDEO,
MEDIA_TYPE_IMAGE,
MEDIA_TYPE_VIDEO,
MediaClass,
MediaType,
)
from homeassistant.components.media_source.error import MediaSourceError, Unresolvable
from homeassistant.components.media_source.models import (
Expand Down Expand Up @@ -174,15 +171,15 @@ def mime_type(self) -> str:
def media_type(self) -> str:
"""Get media type for this frigate media type."""
if self == FrigateMediaType.CLIPS:
return str(MEDIA_TYPE_VIDEO)
return str(MEDIA_TYPE_IMAGE)
return str(MediaType.VIDEO)
return str(MediaType.IMAGE)

@property
def media_class(self) -> str:
"""Get media class for this frigate media type."""
if self == FrigateMediaType.CLIPS:
return str(MEDIA_CLASS_VIDEO)
return str(MEDIA_CLASS_IMAGE)
return str(MediaClass.VIDEO)
return str(MediaClass.IMAGE)

@property
def extension(self) -> str:
Expand Down Expand Up @@ -492,12 +489,12 @@ def mime_type(self) -> str:
@property
def media_class(self) -> str:
"""Get media class for this identifier."""
return str(MEDIA_CLASS_MOVIE)
return str(MediaClass.MOVIE)

@property
def media_type(self) -> str:
"""Get media type for this identifier."""
return str(MEDIA_TYPE_VIDEO)
return str(MediaType.VIDEO)


@attr.s(frozen=True)
Expand Down Expand Up @@ -592,8 +589,8 @@ async def async_browse_media(
domain=DOMAIN,
identifier="",
media_class=MEDIA_CLASS_DIRECTORY,
children_media_class=MEDIA_CLASS_VIDEO,
media_content_type=MEDIA_TYPE_VIDEO,
children_media_class=MediaClass.VIDEO,
media_content_type=MediaType.VIDEO,
title=NAME,
can_play=False,
can_expand=True,
Expand Down Expand Up @@ -858,7 +855,7 @@ def _build_event_response(
media_class=identifier.media_class,
media_content_type=identifier.media_type,
title=f"{dt.datetime.fromtimestamp(event['start_time'], DEFAULT_TIME_ZONE).strftime(DATE_STR_FORMAT)} [{duration}s, {event['label'].capitalize()} {int((event['data'].get('top_score') or event['top_score'] or 0)*100)}%]",
can_play=identifier.media_type == MEDIA_TYPE_VIDEO,
can_play=identifier.media_type == MediaType.VIDEO,
can_expand=False,
thumbnail=f"/api/frigate/{identifier.frigate_instance_id}/thumbnail/{event['id']}",
frigate=FrigateBrowseMediaMetadata(event=event),
Expand Down
Loading