diff --git a/custom_components/yandex_station/camera.py b/custom_components/yandex_station/camera.py index a255a91..fb2d6b0 100644 --- a/custom_components/yandex_station/camera.py +++ b/custom_components/yandex_station/camera.py @@ -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 ) diff --git a/custom_components/yandex_station/core/yandex_station.py b/custom_components/yandex_station/core/yandex_station.py index 44b5a8e..ab324f7 100644 --- a/custom_components/yandex_station/core/yandex_station.py +++ b/custom_components/yandex_station/core/yandex_station.py @@ -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"): @@ -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 diff --git a/tests/test_local.py b/tests/test_local.py index 122d784..edb47f6 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -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 @@ -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", @@ -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 == "Наше радио" @@ -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():