mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 11:33:11 -04:00
Round Music Assistant volume_set level instead of truncating (#196048)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8cdd352686
commit
9591e33efe
@@ -401,7 +401,7 @@ class MusicAssistantPlayer(MusicAssistantEntity, MediaPlayerEntity):
|
||||
@override
|
||||
async def async_set_volume_level(self, volume: float) -> None:
|
||||
"""Send new volume_level to device."""
|
||||
volume = int(volume * 100)
|
||||
volume = round(volume * 100)
|
||||
await self.mass.players.player_command_volume_set(self.player_id, volume)
|
||||
|
||||
@catch_musicassistant_error
|
||||
|
||||
@@ -219,9 +219,21 @@ async def test_media_player_seek_action(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("volume_level", "expected_volume"),
|
||||
[
|
||||
(0.5, 50),
|
||||
# these would land 1% low if truncated (0.29 * 100 == 28.999...)
|
||||
(0.29, 29),
|
||||
(0.57, 57),
|
||||
(0.58, 58),
|
||||
],
|
||||
)
|
||||
async def test_media_player_volume_set_action(
|
||||
hass: HomeAssistant,
|
||||
music_assistant_client: MagicMock,
|
||||
volume_level: float,
|
||||
expected_volume: int,
|
||||
) -> None:
|
||||
"""Test media_player entity volume_set action."""
|
||||
await setup_integration_from_fixtures(hass, music_assistant_client)
|
||||
@@ -234,13 +246,15 @@ async def test_media_player_volume_set_action(
|
||||
MediaPlayerService.VOLUME_SET,
|
||||
{
|
||||
TargetKey.ENTITY_ID: entity_id,
|
||||
MediaPlayerServiceArgument.VOLUME_LEVEL: 0.5,
|
||||
MediaPlayerServiceArgument.VOLUME_LEVEL: volume_level,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert music_assistant_client.send_command.call_count == 1
|
||||
assert music_assistant_client.send_command.call_args == call(
|
||||
"players/cmd/volume_set", player_id=mass_player_id, volume_level=50
|
||||
"players/cmd/volume_set",
|
||||
player_id=mass_player_id,
|
||||
volume_level=expected_volume,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user