* 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>
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."""
# 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