Skip to content

Commit

Permalink
feat: support media source urls
Browse files Browse the repository at this point in the history
  • Loading branch information
EuleMitKeule committed Nov 3, 2024
1 parent 74df4bd commit dcee371
Show file tree
Hide file tree
Showing 4 changed files with 2,529 additions and 1,136 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.yaml": "home-assistant"
}
}
16 changes: 15 additions & 1 deletion custom_components/template_media_player/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
MediaType,
RepeatMode,
)
from homeassistant.components.media_player.browse_media import BrowseMedia
from homeassistant.components.media_player.browse_media import (
BrowseMedia,
async_process_play_media_url,
)
from homeassistant.components.media_source import (
async_resolve_media,
is_media_source_id,
)
from homeassistant.components.template import DOMAIN, PLATFORMS
from homeassistant.components.template.template_entity import TemplateEntity
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_ENTITY_PICTURE_TEMPLATE
Expand Down Expand Up @@ -606,6 +613,13 @@ async def async_play_media(
self, media_type: MediaType | str, media_id: str, **kwargs
):
if CONF_PLAY_MEDIA_SCRIPT in self._service_scripts:
if is_media_source_id(media_id):
media_type = MediaType.MUSIC
play_item = await async_resolve_media(
self.hass, media_id, self.entity_id
)
media_id = async_process_play_media_url(self.hass, play_item.url)

await self._service_scripts[CONF_PLAY_MEDIA_SCRIPT].async_run(
{"media_type": media_type, "media_id": media_id}, context=self._context
)
Expand Down
Loading

0 comments on commit dcee371

Please sign in to comment.