Skip to content

Commit

Permalink
Fix some media_content_type
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 15, 2024
1 parent 869bfb2 commit ee6fea2
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 8 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 in (MediaType.TRACK, MediaType.PLAYLIST):
if entity.media_content_type == MediaType.TRACK:
self.lyrics = await get_lyrics(
self.quasar.session, entity.media_content_id
)
Expand Down
27 changes: 21 additions & 6 deletions custom_components/yandex_station/core/yandex_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,29 @@ def async_set_state(self, data: dict):
self._attr_supported_features = LOCAL_FEATURES

if player_state := state.get("playerState"):
if player_state["liveStreamText"] == "Прямой эфир":
if player_state["type"] == "Track":
self._attr_media_content_type = MediaType.TRACK
elif player_state["type"] == "FmRadio":
self._attr_media_content_type = "radio"
elif player_state["liveStreamText"] == "Прямой эфир":
self._attr_media_content_type = "tv"
elif player_state["playerType"] == "ru.yandex.quasar.app":
self._attr_media_content_type = MediaType.VIDEO
elif player_state["playlistType"] == "Track":
self._attr_media_content_type = MediaType.TRACK
elif player_state["playlistType"] == "FmRadio":
self._attr_media_content_type = "radio"
else:
self._attr_media_content_type = None

if player_state["playlistType"] == "Track":
self._attr_media_playlist = MediaType.TRACK
elif player_state["playlistType"] == "Artist":
self._attr_media_playlist = MediaType.ARTIST
elif player_state["playlistType"] == "Album":
self._attr_media_playlist = MediaType.ALBUM
elif player_state["playlistType"] == "Playlist":
self._attr_media_content_type = MediaType.PLAYLIST
self._attr_media_playlist = MediaType.PLAYLIST
elif player_state["playlistType"] == "FmRadio":
self._attr_media_playlist = "radio"
else:
self._attr_media_playlist = None

if extra := player_state["extra"]:
if url := extra.get("coverURI"):
Expand Down Expand Up @@ -556,8 +569,10 @@ def async_set_state(self, data: dict):
else:
self._attr_media_artist = None
self._attr_media_content_id = None
self._attr_media_content_type = None
self._attr_media_duration = None
self._attr_media_image_url = None
self._attr_media_playlist = None
self._attr_media_position = None
self._attr_media_position_updated_at = None
self._attr_media_title = None
Expand Down
103 changes: 102 additions & 1 deletion tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_track():
assert entity.media_content_id == "37232253"
assert entity.media_content_type == MediaType.TRACK
assert entity.media_duration == 288.0
assert entity.media_playlist == MediaType.TRACK
assert entity.media_position == 244.86800000000002
assert entity.media_title == "Пора возвращаться домой"
assert entity.state == MediaPlayerState.PLAYING
Expand All @@ -102,6 +103,104 @@ def test_track():
)


def test_artist():
state = {
"aliceState": "IDLE",
"canStop": True,
"hdmi": {"capable": False, "present": False},
"playerState": {
"duration": 173.0,
"entityInfo": {
"description": "",
"id": "160970",
"next": {"id": "113351163", "type": "Track"},
"prev": {"id": "123541455", "type": "Track"},
"repeatMode": "None",
"shuffled": False,
"type": "Artist",
},
"extra": {
"coverURI": "avatars.yandex.net/get-music-content/8871869/b35dc4aa.a.25433372-1/%%",
"stateType": "music",
},
"hasNext": True,
"hasPause": True,
"hasPlay": False,
"hasPrev": True,
"hasProgressBar": True,
"id": "40053606",
"liveStreamText": "",
"playerType": "music_thin",
"playlistDescription": "",
"playlistId": "160970",
"playlistPuid": "xxx",
"playlistType": "Artist",
"progress": 120.209,
"showPlayer": False,
"subtitle": "Noize MC",
"title": "Песня для радио",
"type": "Track",
},
"playing": True,
"volume": 0.0,
}

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

assert entity.media_content_type == MediaType.TRACK
assert entity.media_playlist == MediaType.ARTIST


def test_album():
state = {
"aliceState": "IDLE",
"canStop": True,
"hdmi": {"capable": False, "present": False},
"playerState": {
"duration": 303.0,
"entityInfo": {
"description": "",
"id": "10030",
"next": {"id": "38634573", "type": "Track"},
"prev": {"id": "93916267", "type": "Track"},
"repeatMode": "None",
"shuffled": False,
"type": "Album",
},
"extra": {
"coverURI": "avatars.yandex.net/get-music-content/5853241/bc8002a7.a.10030-10/%%",
"stateType": "music",
},
"hasNext": True,
"hasPause": True,
"hasPlay": False,
"hasPrev": True,
"hasProgressBar": True,
"id": "38634572",
"liveStreamText": "",
"playerType": "music_thin",
"playlistDescription": "",
"playlistId": "10030",
"playlistPuid": "xxx",
"playlistType": "Album",
"progress": 5.573,
"showPlayer": False,
"subtitle": "КИНО",
"title": "Песня без слов",
"type": "Track",
},
"playing": True,
"volume": 0.0,
}

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

assert entity.media_content_type == MediaType.TRACK
assert entity.media_playlist == MediaType.ALBUM


def test_radio():
state = {
"aliceState": "IDLE",
Expand Down Expand Up @@ -151,6 +250,7 @@ def test_radio():
assert entity.media_artist is None
assert entity.media_content_type == "radio"
assert entity.media_duration is None
assert entity.media_playlist == "radio"
assert entity.media_title == "Наше радио"


Expand Down Expand Up @@ -200,7 +300,8 @@ def test_podcast():
entity = FakeYandexStation()
entity.async_set_state({"state": state})

assert entity.media_content_type == MediaType.PLAYLIST
assert entity.media_content_type == MediaType.TRACK
assert entity.media_playlist == MediaType.PLAYLIST


def test_video():
Expand Down

0 comments on commit ee6fea2

Please sign in to comment.