Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from davidlb/dev
Browse files Browse the repository at this point in the history
Backport changes made in the master repo + fix warning about deprecated discovery_info.get
  • Loading branch information
davidlb authored May 6, 2022
2 parents e1eafc5 + 8ebeadb commit 85ba2f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/owntone_dleb/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ async def async_step_user(self, user_input=None):
async def async_step_zeroconf(self, discovery_info):
"""Prepare configuration for a discovered forked-daapd device."""
version_num = 0
if discovery_info.get("properties") and discovery_info["properties"].get(
if discovery_info.properties and discovery_info.properties.get(
"Machine Name"
):
with suppress(ValueError):
version_num = int(
discovery_info["properties"].get("mtd-version", "0").split(".")[0]
discovery_info.properties.get("mtd-version", "0").split(".")[0]
)
if version_num < 27:
return self.async_abort(reason="not_forked_daapd")
await self.async_set_unique_id(discovery_info["properties"]["Machine Name"])
await self.async_set_unique_id(discovery_info.properties["Machine Name"])
self._abort_if_unique_id_configured()

# Update title and abort if we already have an entry for this host
Expand Down
2 changes: 2 additions & 0 deletions custom_components/owntone_dleb/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Const for forked-daapd."""
from homeassistant.components.media_player.const import (
SUPPORT_BROWSE_MEDIA,
SUPPORT_CLEAR_PLAYLIST,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
Expand Down Expand Up @@ -74,6 +75,7 @@
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_PLAY_MEDIA
| SUPPORT_BROWSE_MEDIA
)
SUPPORTED_FEATURES_ZONE = (
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | SUPPORT_TURN_ON | SUPPORT_TURN_OFF
Expand Down
18 changes: 18 additions & 0 deletions custom_components/owntone_dleb/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from pyforked_daapd import ForkedDaapdAPI
from pylibrespot_java import LibrespotJavaAPI

from homeassistant.components import media_source
from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.components.media_player.browse_media import (
async_process_play_media_url,
)
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
from homeassistant.const import (
CONF_HOST,
Expand Down Expand Up @@ -631,8 +635,14 @@ async def _pause_and_wait_for_callback(self):

async def async_play_media(self, media_type, media_id, **kwargs):
"""Play a URI."""
if media_source.is_media_source_id(media_id):
media_type = MEDIA_TYPE_MUSIC
play_item = await media_source.async_resolve_media(self.hass, media_id)
media_id = play_item.url

if media_type == MEDIA_TYPE_MUSIC:
_LOGGER.debug("Play Media '%s'", media_id)
""" media_id = async_process_play_media_url(self.hass, media_id) """
await self._api.add_to_queue(uris=media_id, playback="start", clear=True)
else:
_LOGGER.debug("Media type '%s' not supported", media_type)
Expand Down Expand Up @@ -791,3 +801,11 @@ def _add_zones(self, outputs):
self._api,
outputs_to_add,
)

async def async_browse_media(self, media_content_type=None, media_content_id=None):
"""Implement the websocket media browsing helper."""
return await media_source.async_browse_media(
self.hass,
media_content_id,
content_filter=lambda item: item.media_content_type.startswith("audio/"),
)

0 comments on commit 85ba2f1

Please sign in to comment.