Skip to content

Commit

Permalink
Code refactoring after #609
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jan 18, 2025
1 parent 838b0d0 commit 10a97cd
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions custom_components/yandex_station/core/yandex_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,19 +989,22 @@ async def sync_play_media(self, player_state: dict):

source = self.sync_sources[self._attr_source]

#For AirPlay receivers is not possible to change media_content_id, while streaming to device is in progress
#So we need to send media_stop command to media_player instance
#And after streaming is stopped we can send to device new media_content_id
#If we don't do this we got error "already streaming to device"
#Error provided by pyatv component https://github.com/postlund/pyatv
#https://github.com/postlund/pyatv/blob/master/pyatv/protocols/raop/__init__.py at line 132
data_stop = {
"entity_id": source["entity_id"],
}
await self.hass.services.async_call("media_player", "media_stop", data_stop)
#After command is sended, we need to wait while receiver accept command and stop streaming
await asyncio.sleep(1)

if source.get("platform") == "apple_tv":
# For AirPlay receivers is not possible to change media_content_id, while
# streaming to device is in progress. So we need to send media_stop command
# to media_player instance and after streaming is stopped we can send to
# device new media_content_id. If we don't do this we got error "already
# streaming to device".
# Error provided by pyatv component https://github.com/postlund/pyatv
await self.hass.services.async_call(
"media_player",
"media_stop",
{"entity_id": source["entity_id"]},
)
# After command is sended, we need to wait while receiver accept command and
# stop streaming.
await asyncio.sleep(1)

try:
info = await get_file_info(
self.quasar.session,
Expand Down

0 comments on commit 10a97cd

Please sign in to comment.