Skip to content

Commit

Permalink
Merge pull request #305 from emontnemery/cast_platform_ha2022.3
Browse files Browse the repository at this point in the history
Adapt cast platform to changes in HA Core 2022.3
  • Loading branch information
fcusson authored Mar 3, 2022
2 parents 8655f21 + cd485dc commit 013fd58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 6 additions & 18 deletions custom_components/spotcast/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@ async def async_get_media_browser_root_object(
cast_type: str
) -> list[BrowseMedia]:
"""Create a root object for media browsing."""
_LOGGER.debug("async_get_media_browser_root_object")
return [
BrowseMedia(
title="Spotify",
media_class=MEDIA_CLASS_APP,
media_content_id="",
media_content_type="spotify",
thumbnail="https://brands.home-assistant.io/_/spotify/logo.png",
can_play=False,
can_expand=True,
)
]
result = await ha_spotify.async_browse_media(hass, None, None)
_LOGGER.debug("async_get_media_browser_root_object return %s", result.children)
return result.children


async def async_browse_media(
Expand All @@ -49,11 +40,6 @@ async def async_browse_media(
result = await ha_spotify.async_browse_media(
hass, media_content_type, media_content_id, can_play_artist=False
)
if media_content_type == "spotify":
# Browse the root node created by async_get_media_browser_root_object
result = await ha_spotify.async_browse_media(
hass, None, None, can_play_artist=False
)
_LOGGER.debug(
"async_browse_media return: %s",
result
Expand All @@ -77,7 +63,9 @@ async def async_play_media(
# If this is a spotify URI, forward to the the spotcast.start service, if not return
# False
if media_id and media_id.startswith("spotify:"):
data = {"entity_id": cast_entity_id, "uri": media_id}
# Get the spotify URI
spotify_uri = ha_spotify.spotify_uri_from_media_browser_url(media_id)
data = {"entity_id": cast_entity_id, "uri": spotify_uri}
await hass.services.async_call("spotcast", "start", data, blocking=False)
return True
return False
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Spotcast",
"domains": ["media_player", "sensor"],
"homeassistant": "2021.12.0",
"homeassistant": "2022.3.0",
"iot_class": ["Cloud Polling"]
}

0 comments on commit 013fd58

Please sign in to comment.