Skip to content

Commit 8eee530

Browse files
PeteRagerfrenck
authored andcommitted
Fix Sonos set_volume float precision issue (home-assistant#152493)
1 parent b37237d commit 8eee530

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

homeassistant/components/sonos/media_player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def volume_down(self) -> None:
410410
@soco_error()
411411
def set_volume_level(self, volume: float) -> None:
412412
"""Set volume level, range 0..1."""
413-
self.soco.volume = int(volume * 100)
413+
self.soco.volume = int(round(volume * 100))
414414

415415
@soco_error(UPNP_ERRORS_TO_IGNORE)
416416
def set_shuffle(self, shuffle: bool) -> None:

tests/components/sonos/test_media_player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,11 @@ async def test_volume(
11011101
await hass.services.async_call(
11021102
MP_DOMAIN,
11031103
SERVICE_VOLUME_SET,
1104-
{ATTR_ENTITY_ID: "media_player.zone_a", ATTR_MEDIA_VOLUME_LEVEL: 0.30},
1104+
{ATTR_ENTITY_ID: "media_player.zone_a", ATTR_MEDIA_VOLUME_LEVEL: 0.57},
11051105
blocking=True,
11061106
)
11071107
# SoCo uses 0..100 for its range.
1108-
assert soco.volume == 30
1108+
assert soco.volume == 57
11091109

11101110

11111111
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)