Fix Sonos set_volume float precision issue (#152493)

This commit is contained in:
Pete Sage
2025-09-17 08:39:28 -04:00
committed by GitHub
parent a4f15e4840
commit 804b42e1fb
2 changed files with 3 additions and 3 deletions

View File

@@ -305,7 +305,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
@soco_error()
def set_volume_level(self, volume: float) -> None:
"""Set volume level, range 0..1."""
self.soco.volume = int(volume * 100)
self.soco.volume = int(round(volume * 100))
@soco_error(UPNP_ERRORS_TO_IGNORE)
def set_shuffle(self, shuffle: bool) -> None:

View File

@@ -1103,11 +1103,11 @@ async def test_volume(
await hass.services.async_call(
MP_DOMAIN,
SERVICE_VOLUME_SET,
{ATTR_ENTITY_ID: "media_player.zone_a", ATTR_MEDIA_VOLUME_LEVEL: 0.30},
{ATTR_ENTITY_ID: "media_player.zone_a", ATTR_MEDIA_VOLUME_LEVEL: 0.57},
blocking=True,
)
# SoCo uses 0..100 for its range.
assert soco.volume == 30
assert soco.volume == 57
@pytest.mark.parametrize(