Skip to content

Commit

Permalink
Update content type for support default media card
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 16, 2024
1 parent d871668 commit fee57c7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 33 deletions.
2 changes: 1 addition & 1 deletion custom_components/yandex_station/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async def get_lyrics(self) -> str | None:
return None

if self.lyrics_content_id != entity.media_content_id:
if entity.media_content_type == MediaType.TRACK:
if entity.media_content_type == MediaType.MUSIC:
self.lyrics = await get_lyrics(
self.quasar.session, entity.media_content_id
)
Expand Down
16 changes: 12 additions & 4 deletions custom_components/yandex_station/core/yandex_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,17 +515,23 @@ def async_set_state(self, data: dict):
self._attr_assumed_state = False
self._attr_available = True
self._attr_should_poll = False
self._attr_shuffle = None
self._attr_supported_features = LOCAL_FEATURES

if player_state := state.get("playerState"):
# https://github.com/home-assistant/frontend/blob/dev/src/data/media-player.ts
# supported computeMediaDescription: music/image/playlist/tvshow/channel
if player_state["type"] == "Track":
self._attr_media_content_type = MediaType.TRACK
self._attr_media_artist = player_state["subtitle"] or None
self._attr_media_content_type = MediaType.MUSIC
elif player_state["type"] == "FmRadio":
self._attr_media_content_type = "radio"
elif player_state["liveStreamText"] == "Прямой эфир":
self._attr_media_content_type = "tv"
self._attr_media_channel = player_state["subtitle"] or None
self._attr_media_content_type = MediaType.CHANNEL
elif player_state["playerType"] == "ru.yandex.quasar.app":
self._attr_media_content_type = MediaType.VIDEO
self._attr_media_content_type = MediaType.TVSHOW
self._attr_media_series_title = player_state["subtitle"] or None
else:
self._attr_media_content_type = None

Expand All @@ -547,7 +553,9 @@ def async_set_state(self, data: dict):
url = "https://" + url.replace("%%", "400x400")
self._attr_media_image_url = url

self._attr_media_artist = player_state["subtitle"] or None
if "shuffled" in player_state["entityInfo"]:
self._attr_shuffle = player_state["entityInfo"]["shuffled"]

self._attr_media_content_id = player_state["id"]
self._attr_media_duration = player_state["duration"] or None
self._attr_media_position = player_state["progress"]
Expand Down
77 changes: 49 additions & 28 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ def test_track():
assert entity.extra_state_attributes == {"alice_state": "IDLE"}
assert entity.media_artist == "Би-2"
assert entity.media_content_id == "37232253"
assert entity.media_content_type == MediaType.TRACK
assert entity.media_content_type == MediaType.MUSIC
assert entity.media_duration == 288.0
assert entity.media_playlist == MediaType.TRACK
assert entity.media_position == 244.86800000000002
assert entity.media_title == "Пора возвращаться домой"
assert entity.shuffle is None
assert entity.state == MediaPlayerState.PLAYING
assert entity.volume_level == 0.4

Expand Down Expand Up @@ -148,8 +149,10 @@ def test_artist():
entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == MediaType.TRACK
assert entity.media_content_id == "40053606"
assert entity.media_content_type == MediaType.MUSIC
assert entity.media_playlist == MediaType.ARTIST
assert entity.shuffle is False


def test_album():
Expand Down Expand Up @@ -197,8 +200,10 @@ def test_album():
entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == MediaType.TRACK
assert entity.media_content_id == "38634572"
assert entity.media_content_type == MediaType.MUSIC
assert entity.media_playlist == MediaType.ALBUM
assert entity.shuffle is False


def test_radio():
Expand Down Expand Up @@ -248,10 +253,12 @@ def test_radio():
entity.async_set_state({"state": state})

assert entity.media_artist is None
assert entity.media_content_id == "nashe"
assert entity.media_content_type == "radio"
assert entity.media_duration is None
assert entity.media_playlist == "radio"
assert entity.media_title == "Наше радио"
assert entity.shuffle is False


def test_podcast():
Expand Down Expand Up @@ -300,83 +307,93 @@ def test_podcast():
entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == MediaType.TRACK
assert entity.media_content_id == "124374440"
assert entity.media_content_type == MediaType.MUSIC
assert entity.media_playlist == MediaType.PLAYLIST
assert entity.shuffle is False


def test_video():
def test_tv():
state = {
"aliceState": "IDLE",
"aliceState": "LISTENING",
"canStop": True,
"hdmi": {"capable": True, "present": False},
"playerState": {
"duration": 351.0,
"duration": 0.0,
"entityInfo": {"description": "", "id": "", "type": ""},
"extra": {},
"hasNext": True,
"hasNext": False,
"hasPause": True,
"hasPlay": False,
"hasPrev": False,
"hasProgressBar": True,
"id": "4e0a11ba3b549da0b7291235f8a50c2e",
"liveStreamText": "",
"hasProgressBar": False,
"id": "49128833ca298c65b565d5d93761e759",
"liveStreamText": "Прямой эфир",
"playerType": "ru.yandex.quasar.app",
"playlistDescription": "",
"playlistId": "",
"playlistPuid": "",
"playlistType": "",
"progress": 27.0,
"progress": 0.0,
"showPlayer": True,
"subtitle": "Фиксики, 1 сезон, 1 серия",
"title": "Фиксики - Сезон 1 - Серия 1 - Сифон",
"subtitle": "360 Новости — Новости 360",
"title": "Новости 360",
"type": "",
},
"playing": True,
"timeSinceLastVoiceActivity": 33,
"volume": 0.2,
}

entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == MediaType.VIDEO
assert entity.media_artist is None
assert entity.media_content_id == "49128833ca298c65b565d5d93761e759"
assert entity.media_content_type == MediaType.CHANNEL
assert entity.media_channel == "360 Новости — Новости 360"
assert entity.shuffle is None


def test_tv():
def test_video():
state = {
"aliceState": "LISTENING",
"aliceState": "IDLE",
"canStop": True,
"hdmi": {"capable": True, "present": False},
"playerState": {
"duration": 0.0,
"duration": 351.0,
"entityInfo": {"description": "", "id": "", "type": ""},
"extra": {},
"hasNext": False,
"hasNext": True,
"hasPause": True,
"hasPlay": False,
"hasPrev": False,
"hasProgressBar": False,
"id": "49128833ca298c65b565d5d93761e759",
"liveStreamText": "Прямой эфир",
"hasProgressBar": True,
"id": "4e0a11ba3b549da0b7291235f8a50c2e",
"liveStreamText": "",
"playerType": "ru.yandex.quasar.app",
"playlistDescription": "",
"playlistId": "",
"playlistPuid": "",
"playlistType": "",
"progress": 0.0,
"progress": 27.0,
"showPlayer": True,
"subtitle": "360 Новости — Новости 360",
"title": "Новости 360",
"subtitle": "Фиксики, 1 сезон, 1 серия",
"title": "Фиксики - Сезон 1 - Серия 1 - Сифон",
"type": "",
},
"playing": True,
"timeSinceLastVoiceActivity": 33,
"volume": 0.2,
}

entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == "tv"
assert entity.media_artist is None
assert entity.media_content_id == "4e0a11ba3b549da0b7291235f8a50c2e"
assert entity.media_content_type == MediaType.TVSHOW
assert entity.media_series_title == "Фиксики, 1 сезон, 1 серия"
assert entity.shuffle is None


def test_movie():
Expand Down Expand Up @@ -413,4 +430,8 @@ def test_movie():
entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == MediaType.VIDEO
assert entity.media_artist is None
assert entity.media_content_id == "402f8e529e4e7a31b3b43f4383cbc10d"
assert entity.media_content_type == MediaType.TVSHOW
assert entity.media_series_title == "военный, боевик, история, биография, 18+, 2019"
assert entity.shuffle is None

0 comments on commit fee57c7

Please sign in to comment.