Skip to content

Commit

Permalink
Replace MEDIA_CLASS_ and MEDIA_TYPE_ with MediaClass and MediaType (#726
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TheZoker authored Sep 28, 2024
1 parent 070fbf2 commit 4f715ea
Showing 1 changed file with 11 additions and 14 deletions.
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

0 comments on commit 4f715ea

Please sign in to comment.