Skip to content

Commit

Permalink
Fix overlay custom service not working
Browse files Browse the repository at this point in the history
  • Loading branch information
mj23000 committed Dec 8, 2023
1 parent cf6df6d commit 401d940
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion custom_components/bangolufsen/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/bang-olufsen/bangolufsen-hacs/issues",
"requirements": ["mozart-api==3.2.1.150.5"],
"version": "1.6.0",
"version": "1.6.1",
"zeroconf": ["_bangolufsen._tcp.local."]
}
26 changes: 11 additions & 15 deletions custom_components/bangolufsen/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class BangOlufsenMediaPlayer(MediaPlayerEntity, CoordinatorEntity, BangOlufsenEn

def __init__(self, entry: ConfigEntry, data: BangOlufsenData) -> None:
"""Initialize the media player."""
MediaPlayerEntity.__init__(self)
CoordinatorEntity.__init__(self, data.coordinator)
BangOlufsenEntity.__init__(self, entry, data.client)

Expand Down Expand Up @@ -1301,16 +1302,18 @@ async def async_overlay_audio(
_LOGGER.error("Can't define URI and TTS message at the same time")
return

volume = None
overlay_play_request = OverlayPlayRequest()

if absolute_volume:
volume = absolute_volume
overlay_play_request.volume_absolute = absolute_volume
elif volume_offset:
# Ensure that the volume is not above 100
if not self._volume.level or not self._volume.level.level:
_LOGGER.warning("Error setting volume")
else:
volume = min(self._volume.level.level + volume_offset, 100)
overlay_play_request.volume_absolute = min(
self._volume.level.level + volume_offset, 100
)

if uri:
media_id = uri
Expand All @@ -1323,18 +1326,11 @@ async def async_overlay_audio(

media_id = async_process_play_media_url(self.hass, sourced_media.url)

await self._client.post_overlay_play(
overlay_play_request=OverlayPlayRequest(
uri=Uri(location=media_id), volume_absolute=volume
)
)
overlay_play_request.uri = Uri(location=media_id)

elif tts:
await self._client.post_overlay_play(
overlay_play_request=OverlayPlayRequest(
text_to_speech=OverlayPlayRequestTextToSpeechTextToSpeech(
lang=tts_language, text=tts
),
volume_absolute=volume,
)
overlay_play_request.text_to_speech = (
OverlayPlayRequestTextToSpeechTextToSpeech(lang=tts_language, text=tts)
)

await self._client.post_overlay_play(overlay_play_request)

0 comments on commit 401d940

Please sign in to comment.