From 1e9e0c8686b6bee458bf8fba4a8b5cbdd12f3b95 Mon Sep 17 00:00:00 2001 From: willholdoway Date: Thu, 8 Oct 2020 19:20:39 +0100 Subject: [PATCH] Add mute command to Bluesound integration (#41501) Adding mute as a separate command as per the Bluesound API, rather than the current pseudo-mute which is achieved via lowering the volume to 0 then detecting whether the volume is 0 < volume < 0.001 --- .../components/bluesound/media_player.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index c0088cb4a2a..0ace6f5679a 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -220,7 +220,7 @@ class BluesoundPlayer(MediaPlayerEntity): self._last_status_update = None self._is_online = False self._retry_remove = None - self._lastvol = None + self._muted = False self._master = None self._is_master = False self._group_name = None @@ -660,10 +660,13 @@ class BluesoundPlayer(MediaPlayerEntity): @property def is_volume_muted(self): """Boolean if volume is currently muted.""" - volume = self.volume_level - if not volume: - return None - return 0 <= volume < 0.001 + mute = self._status.get("mute") + if self.is_grouped: + mute = self._sync_status.get("@mute") + + if mute is not None: + mute = bool(int(mute)) + return mute @property def name(self): @@ -1044,10 +1047,5 @@ class BluesoundPlayer(MediaPlayerEntity): async def async_mute_volume(self, mute): """Send mute command to media player.""" if mute: - volume = self.volume_level - if volume > 0: - self._lastvol = volume - return await self.send_bluesound_command("Volume?level=0") - return await self.send_bluesound_command( - f"Volume?level={float(self._lastvol) * 100}" - ) + return await self.send_bluesound_command("Volume?mute=1") + return await self.send_bluesound_command("Volume?mute=0")