From: OzGav Date: Fri, 21 Nov 2025 15:26:29 +0000 (+1000) Subject: Fix Chromecast volume rounding bug (#2656) X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=dba12e4f106be03411c9ba7889af7f34e50e13f4;p=music-assistant-server.git Fix Chromecast volume rounding bug (#2656) * Fix Chromecast volume rounding bug for values 8% and below Changed volume level conversion from int() to round() to fix floating-point precision issues. Chromecast reports volume as float (0.0-1.0) which can have slight imprecision (e.g., 4% = 0.03999999910593033). Using int() truncated these values, causing displayed volume to be 1% less than actual for values 8% and below. Fixes the issue where setting volume to 5% would display as 4%, etc. * Fix Chromecast volume rounding bug for values 8% and below Changed volume level conversion to use round() instead of int() in both directions to fix floating-point precision issues: 1. When setting volume: round to 2 decimal places before sending to device 2. When reading volume: round to nearest integer when converting to percentage This fixes the issue where Chromecast reports volume as float (0.0-1.0) with slight imprecision (e.g., 4% = 0.03999999910593033). Using int() truncated these values, causing displayed volume to be 1% less than actual for values 8% and below. Fixes the issue where setting volume to 5% would display as 4%, etc. --------- Co-authored-by: Claude Co-authored-by: Marvin Schenkel --- diff --git a/music_assistant/providers/chromecast/player.py b/music_assistant/providers/chromecast/player.py index 506da070..309d8f29 100644 --- a/music_assistant/providers/chromecast/player.py +++ b/music_assistant/providers/chromecast/player.py @@ -161,7 +161,8 @@ class ChromecastPlayer(Player): async def volume_set(self, volume_level: int) -> None: """Send VOLUME_SET command to given player.""" - await asyncio.to_thread(self.cc.set_volume, volume_level / 100) + # Round to 2 decimal places to avoid floating-point precision issues + await asyncio.to_thread(self.cc.set_volume, round(volume_level / 100, 2)) async def volume_mute(self, muted: bool) -> None: """Send VOLUME MUTE command to given player.""" @@ -388,7 +389,7 @@ class ChromecastPlayer(Player): # update player status self._attr_name = self.cast_info.friendly_name - self._attr_volume_level = int(status.volume_level * 100) + self._attr_volume_level = round(status.volume_level * 100) self._attr_volume_muted = status.volume_muted new_powered = self.cc.app_id is not None and self.cc.app_id != IDLE_APP_ID self._attr_powered = new_powered