Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add media position & seek to Russound RIO #134372

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions homeassistant/components/russound_rio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import datetime as dt
import logging
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -57,6 +58,7 @@ class RussoundZoneDevice(RussoundBaseEntity, MediaPlayerEntity):
| MediaPlayerEntityFeature.TURN_ON
| MediaPlayerEntityFeature.TURN_OFF
| MediaPlayerEntityFeature.SELECT_SOURCE
| MediaPlayerEntityFeature.SEEK
)

def __init__(
Expand Down Expand Up @@ -138,6 +140,21 @@ def media_image_url(self) -> str | None:
"""Image url of current playing media."""
return self._source.cover_art_url

@property
def media_duration(self) -> int | None:
"""Duration of the current media."""
return self._source.track_time

@property
def media_position(self) -> int | None:
"""Position of the current media."""
return self._source.play_time

@property
def media_position_updated_at(self) -> dt.datetime:
"""Last time the media position was updated."""
return self._source.position_last_updated

@property
def volume_level(self) -> float:
"""Volume level of the media player (0..1).
Expand Down Expand Up @@ -199,3 +216,8 @@ async def async_mute_volume(self, mute: bool) -> None:

if mute != self.is_volume_muted:
await self._zone.toggle_mute()

@command
async def async_media_seek(self, position: float) -> None:
"""Seek to a position in the current media."""
await self._zone.set_seek_time(int(position))
1 change: 1 addition & 0 deletions tests/components/russound_rio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def mock_russound_client() -> Generator[AsyncMock]:
zone.mute = AsyncMock()
zone.unmute = AsyncMock()
zone.toggle_mute = AsyncMock()
zone.set_seek_time = AsyncMock()

client.controllers = {
1: Controller(
Expand Down
21 changes: 21 additions & 0 deletions tests/components/russound_rio/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

from homeassistant.components.media_player import (
ATTR_INPUT_SOURCE,
ATTR_MEDIA_SEEK_POSITION,
ATTR_MEDIA_VOLUME_LEVEL,
ATTR_MEDIA_VOLUME_MUTED,
DOMAIN as MP_DOMAIN,
SERVICE_SELECT_SOURCE,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
SERVICE_MEDIA_SEEK,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
SERVICE_VOLUME_DOWN,
Expand Down Expand Up @@ -232,3 +234,22 @@ async def test_power_service(
await hass.services.async_call(MP_DOMAIN, SERVICE_TURN_OFF, data, blocking=True)

mock_russound_client.controllers[1].zones[1].zone_off.assert_called_once()


async def test_media_seek(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_russound_client: AsyncMock,
) -> None:
"""Test media seek service."""
await setup_integration(hass, mock_config_entry)

await hass.services.async_call(
MP_DOMAIN,
SERVICE_MEDIA_SEEK,
{ATTR_ENTITY_ID: ENTITY_ID_ZONE_1, ATTR_MEDIA_SEEK_POSITION: 100},
)

mock_russound_client.controllers[1].zones[1].set_seek_time.assert_called_once_with(
noahhusby marked this conversation as resolved.
Show resolved Hide resolved
100
)