Skip to content

Commit

Permalink
Adds support MediaBrowser #260
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 9, 2022
1 parent 32efc8d commit 31bb564
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/yandex_station/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"documentation": "https://github.com/AlexxIT/YandexStation",
"issue_tracker": "https://github.com/AlexxIT/YandexStation/issues",
"codeowners": ["@AlexxIT"],
"dependencies": ["http", "tts", "zeroconf"],
"dependencies": ["http", "zeroconf"],
"requirements": [],
"version": "3.9.1",
"iot_class": "local_push"
Expand Down
24 changes: 20 additions & 4 deletions custom_components/yandex_station/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import uuid
from datetime import timedelta
from typing import Optional
from urllib import parse

import yaml
from homeassistant.components import shopping_list
from homeassistant.components.media_player import *
from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.components.media_player.const import MEDIA_TYPE_TVSHOW, \
MEDIA_TYPE_CHANNEL
from homeassistant.components.media_player.const import (
MEDIA_TYPE_TVSHOW, MEDIA_TYPE_CHANNEL
)
from homeassistant.components.media_source.models import BrowseMediaSource
from homeassistant.const import STATE_PLAYING, STATE_PAUSED, STATE_IDLE
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -36,7 +38,7 @@
BASE_FEATURES = (
SUPPORT_TURN_OFF | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_STEP |
SUPPORT_VOLUME_MUTE | SUPPORT_PLAY_MEDIA | SUPPORT_SELECT_SOUND_MODE |
SUPPORT_TURN_ON
SUPPORT_TURN_ON | SUPPORT_BROWSE_MEDIA
)

CLOUD_FEATURES = (
Expand Down Expand Up @@ -748,11 +750,17 @@ async def async_update(self):
async def async_play_media(
self, media_type: str, media_id: str, extra: dict = None, **kwargs
):
# backward support Hass lower than v2022.3
if '/api/tts_proxy/' in media_id:
session = async_get_clientsession(self.hass)
media_id = await utils.get_tts_message(session, media_id)
media_type = 'tts'

if media_type == "provider":
query: dict = parse.parse_qs(parse.urlparse(media_id).query)
media_id = query["message"][0]
media_type = 'tts'

if not media_id:
_LOGGER.warning(f"Получено пустое media_id")
return
Expand Down Expand Up @@ -855,6 +863,14 @@ async def async_play_media(
_LOGGER.warning(f"Unsupported cloud media: {media_type}")
return

async def async_browse_media(
self, media_content_type: str = None, media_content_id: str = None,
) -> BrowseMedia:
return BrowseMediaSource(
domain="tts", identifier=DOMAIN, media_class=None, title=self.name,
media_content_type="provider", can_play=False, can_expand=False,
)


# noinspection PyAbstractClass
class YandexModule(YandexStation):
Expand Down

1 comment on commit 31bb564

@AlexxIT
Copy link
Owner Author

@AlexxIT AlexxIT commented on 31bb564 May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.