Skip to content

Commit

Permalink
Improved streaming metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jan 17, 2025
1 parent 2c06b4b commit 4e3320c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
11 changes: 11 additions & 0 deletions custom_components/yandex_station/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ async def action(event, updates: list[TrackTemplateResult]):
return track.async_remove


def get_platform(hass: HomeAssistant, entity_id: str) -> str | None:
try:
ec: EntityComponent = hass.data["entity_components"]["media_player"]
for entity in ec.entities:
if entity.entity_id == entity_id:
return entity.platform.platform_name
except:
pass
return None


MIME_TYPES = {"aac": "audio/aac", "flac": "audio/x-flac", "mp3": "audio/mpeg"}


Expand Down
27 changes: 16 additions & 11 deletions custom_components/yandex_station/core/yandex_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ async def init_local_mode(self):

self._attr_source_list += list(self.sync_sources.keys())

async def async_select_source(self, source):
async def async_select_source(self, source: str):
if self.sync_mute is True:
# включаем звук колонке, если выключали его
self.hass.create_task(self.async_mute_volume(False))
Expand All @@ -937,7 +937,12 @@ async def async_select_source(self, source):

await super().async_select_source(source)

self.sync_enabled = self.sync_sources and source in self.sync_sources
if self.sync_sources and (source := self.sync_sources.get(source)):
self.sync_enabled = True
if "platform" not in source:
source["platform"] = utils.get_platform(self.hass, source["entity_id"])
else:
self.sync_enabled = False

@callback
def async_set_state(self, data: dict):
Expand Down Expand Up @@ -1003,18 +1008,18 @@ async def sync_play_media(self, player_state: dict):
),
"media_content_type": source.get("media_content_type", "music"),
"entity_id": source["entity_id"],
"extra": {
}

if source.get("platform") == "cast":
data["extra"] = {
"stream_type": "BUFFERED",
"metadata": {
"metadataType": 3,
"title": f"{self._attr_media_title}",
"artist": f"{self._attr_media_artist}",
"images": [{
"url": self._attr_media_image_url
}]
}
},
}
"title": self._attr_media_title,
"artist": self._attr_media_artist,
"images": [{"url": self._attr_media_image_url}],
},
}

await self.hass.services.async_call("media_player", "play_media", data)

Expand Down

0 comments on commit 4e3320c

Please sign in to comment.