Add Sonos tests for media_player volume (#122283)
This commit is contained in:
parent
86bfc7ada8
commit
cfef72ae57
2 changed files with 46 additions and 2 deletions
|
@ -388,7 +388,7 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
@soco_error()
|
||||
def set_volume_level(self, volume: float) -> None:
|
||||
"""Set volume level, range 0..1."""
|
||||
self.soco.volume = str(int(volume * 100))
|
||||
self.soco.volume = int(volume * 100)
|
||||
|
||||
@soco_error(UPNP_ERRORS_TO_IGNORE)
|
||||
def set_shuffle(self, shuffle: bool) -> None:
|
||||
|
|
|
@ -22,8 +22,14 @@ from homeassistant.components.sonos.media_player import (
|
|||
LONG_SERVICE_TIMEOUT,
|
||||
SERVICE_RESTORE,
|
||||
SERVICE_SNAPSHOT,
|
||||
VOLUME_INCREMENT,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
SERVICE_VOLUME_DOWN,
|
||||
SERVICE_VOLUME_SET,
|
||||
SERVICE_VOLUME_UP,
|
||||
STATE_IDLE,
|
||||
)
|
||||
from homeassistant.const import STATE_IDLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers.device_registry import (
|
||||
|
@ -768,3 +774,41 @@ async def test_service_snapshot_restore(
|
|||
blocking=True,
|
||||
)
|
||||
assert mock_restore.call_count == 2
|
||||
|
||||
|
||||
async def test_volume(
|
||||
hass: HomeAssistant,
|
||||
soco: MockSoCo,
|
||||
async_autosetup_sonos,
|
||||
) -> None:
|
||||
"""Test the media player volume services."""
|
||||
initial_volume = soco.volume
|
||||
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_UP,
|
||||
{
|
||||
"entity_id": "media_player.zone_a",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert soco.volume == initial_volume + VOLUME_INCREMENT
|
||||
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_DOWN,
|
||||
{
|
||||
"entity_id": "media_player.zone_a",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert soco.volume == initial_volume
|
||||
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_VOLUME_SET,
|
||||
{"entity_id": "media_player.zone_a", "volume_level": 0.30},
|
||||
blocking=True,
|
||||
)
|
||||
# SoCo uses 0..100 for its range.
|
||||
assert soco.volume == 30
|
||||
|
|
Loading…
Add table
Reference in a new issue