Fix Chromecast volume rounding bug (#2656)
authorOzGav <gavnosp@hotmail.com>
Fri, 21 Nov 2025 15:26:29 +0000 (01:26 +1000)
committerGitHub <noreply@github.com>
Fri, 21 Nov 2025 15:26:29 +0000 (15:26 +0000)
commitdba12e4f106be03411c9ba7889af7f34e50e13f4
tree1519a682e0035ef1fc45695dd25a4840cfad78aa
parent723951059e4e38b0b986d5496a516a098ba4d4a1
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 <noreply@anthropic.com>
Co-authored-by: Marvin Schenkel <marvinschenkel@gmail.com>
music_assistant/providers/chromecast/player.py