mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Refactor forked_daapd to use _async_announce (#78446)
This commit is contained in:
parent
5cccb24830
commit
13c7a7bbcc
@ -668,6 +668,11 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||||||
if media_type == MediaType.MUSIC:
|
if media_type == MediaType.MUSIC:
|
||||||
media_id = async_process_play_media_url(self.hass, media_id)
|
media_id = async_process_play_media_url(self.hass, media_id)
|
||||||
|
|
||||||
|
await self._async_announce(media_id)
|
||||||
|
else:
|
||||||
|
_LOGGER.debug("Media type '%s' not supported", media_type)
|
||||||
|
|
||||||
|
async def _async_announce(self, media_id: str):
|
||||||
saved_state = self.state # save play state
|
saved_state = self.state # save play state
|
||||||
saved_mute = self.is_volume_muted
|
saved_mute = self.is_volume_muted
|
||||||
sleep_future = asyncio.create_task(
|
sleep_future = asyncio.create_task(
|
||||||
@ -677,9 +682,7 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||||||
await self._save_and_set_tts_volumes()
|
await self._save_and_set_tts_volumes()
|
||||||
# save position
|
# save position
|
||||||
saved_song_position = self._player["item_progress_ms"]
|
saved_song_position = self._player["item_progress_ms"]
|
||||||
saved_queue = (
|
saved_queue = self._queue if self._queue["count"] > 0 else None # stash queue
|
||||||
self._queue if self._queue["count"] > 0 else None
|
|
||||||
) # stash queue
|
|
||||||
if saved_queue:
|
if saved_queue:
|
||||||
saved_queue_position = next(
|
saved_queue_position = next(
|
||||||
i
|
i
|
||||||
@ -690,9 +693,7 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||||||
await sleep_future
|
await sleep_future
|
||||||
await self._api.add_to_queue(uris=media_id, playback="start", clear=True)
|
await self._api.add_to_queue(uris=media_id, playback="start", clear=True)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(
|
await asyncio.wait_for(self._tts_playing_event.wait(), timeout=TTS_TIMEOUT)
|
||||||
self._tts_playing_event.wait(), timeout=TTS_TIMEOUT
|
|
||||||
)
|
|
||||||
# we have started TTS, now wait for completion
|
# we have started TTS, now wait for completion
|
||||||
await asyncio.sleep(
|
await asyncio.sleep(
|
||||||
self._queue["items"][0]["length_ms"]
|
self._queue["items"][0]["length_ms"]
|
||||||
@ -729,8 +730,6 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||||||
await self.async_media_pause()
|
await self.async_media_pause()
|
||||||
elif saved_state != MediaPlayerState.PLAYING:
|
elif saved_state != MediaPlayerState.PLAYING:
|
||||||
await self.async_media_stop()
|
await self.async_media_stop()
|
||||||
else:
|
|
||||||
_LOGGER.debug("Media type '%s' not supported", media_type)
|
|
||||||
|
|
||||||
async def async_select_source(self, source: str) -> None:
|
async def async_select_source(self, source: str) -> None:
|
||||||
"""Change source.
|
"""Change source.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user