Skip to content

Commit

Permalink
Fix volume_up not working in some cases in bluesound integration (#13…
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisChrist authored and frenck committed Nov 8, 2024
1 parent 2fe4fc9 commit 1bb0ced
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ async def async_volume_down(self) -> None:

async def async_set_volume_level(self, volume: float) -> None:
"""Send volume_up command to media player."""
volume = int(volume * 100)
volume = int(round(volume * 100))
volume = min(100, volume)
volume = max(0, volume)

Expand Down
28 changes: 28 additions & 0 deletions tests/components/bluesound/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,31 @@ async def test_attr_bluesound_group(
).attributes.get("bluesound_group")

assert attr_bluesound_group == ["player-name1111", "player-name2222"]


async def test_volume_up_from_6_to_7(
hass: HomeAssistant,
setup_config_entry: None,
player_mocks: PlayerMocks,
) -> None:
"""Test the media player volume up from 6 to 7.
This fails if if rounding is not done correctly. See https://github.com/home-assistant/core/issues/129956 for more details.
"""
player_mocks.player_data.status_long_polling_mock.set(
dataclasses.replace(
player_mocks.player_data.status_long_polling_mock.get(), volume=6
)
)

# give the long polling loop a chance to update the state; this could be any async call
await hass.async_block_till_done()

await hass.services.async_call(
MEDIA_PLAYER_DOMAIN,
SERVICE_VOLUME_UP,
{ATTR_ENTITY_ID: "media_player.player_name1111"},
blocking=True,
)

player_mocks.player_data.player.volume.assert_called_once_with(level=7)

0 comments on commit 1bb0ced

Please sign in to comment.