Use internal url for Squeezebox if possible (#43089)

This commit is contained in:
Paulus Schoutsen 2020-11-11 14:49:08 +01:00 committed by GitHub
parent 1061f78f12
commit 560afc31ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -13,6 +13,7 @@ from homeassistant.components.media_player.const import (
MEDIA_TYPE_PLAYLIST,
MEDIA_TYPE_TRACK,
)
from homeassistant.helpers.network import is_internal_request
LIBRARY = ["Artists", "Albums", "Tracks", "Playlists", "Genres"]
@ -67,6 +68,8 @@ BROWSE_LIMIT = 1000
async def build_item_response(entity, player, payload):
"""Create response payload for search described by payload."""
internal_request = is_internal_request(entity.hass)
search_id = payload["search_id"]
search_type = payload["search_type"]
@ -96,9 +99,14 @@ async def build_item_response(entity, player, payload):
artwork_track_id = item.get("artwork_track_id")
if artwork_track_id:
item_thumbnail = entity.get_browse_image_url(
item_type, item_id, artwork_track_id
)
if internal_request:
item_thumbnail = player.generate_image_url_from_track_id(
artwork_track_id
)
else:
item_thumbnail = entity.get_browse_image_url(
item_type, item_id, artwork_track_id
)
children.append(
BrowseMedia(

View File

@ -24,6 +24,16 @@ class NoURLAvailableError(HomeAssistantError):
"""An URL to the Home Assistant instance is not available."""
@bind_hass
def is_internal_request(hass: HomeAssistant) -> bool:
"""Test if the current request is internal."""
try:
_get_internal_url(hass, require_current_request=True)
return True
except NoURLAvailableError:
return False
@bind_hass
def get_url(
hass: HomeAssistant,