Skip to content

Commit

Permalink
Address late review of system bridge media source (home-assistant#77032)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
  • Loading branch information
timmo001 and MartinHjelmare authored Aug 19, 2022
1 parent 98c9399 commit a076d3f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions homeassistant/components/system_bridge/media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def _build_base_url(
entry: ConfigEntry,
) -> str:
"""Build base url for System Bridge media."""
return f"http://{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}/api/media/file/data?apiKey={entry.data[CONF_API_KEY]}"
return (
f"http://{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}"
f"/api/media/file/data?apiKey={entry.data[CONF_API_KEY]}"
)


def _build_root_paths(
Expand Down Expand Up @@ -191,17 +194,19 @@ def _build_media_item(
media_file: MediaFile,
) -> BrowseMediaSource:
"""Build individual media item."""
ext = (
f"~~{media_file.mime_type}"
if media_file.is_file and media_file.mime_type is not None
else ""
)
ext = ""
if media_file.is_file and media_file.mime_type is not None:
ext = f"~~{media_file.mime_type}"

if media_file.is_directory or media_file.mime_type is None:
media_class = MEDIA_CLASS_DIRECTORY
else:
media_class = MEDIA_CLASS_MAP[media_file.mime_type.split("/", 1)[0]]

return BrowseMediaSource(
domain=DOMAIN,
identifier=f"{path}/{media_file.name}{ext}",
media_class=MEDIA_CLASS_DIRECTORY
if media_file.is_directory or media_file.mime_type is None
else MEDIA_CLASS_MAP[media_file.mime_type.split("/", 1)[0]],
media_class=media_class,
media_content_type=media_file.mime_type,
title=media_file.name,
can_play=media_file.is_file,
Expand Down

0 comments on commit a076d3f

Please sign in to comment.