mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Support additional media player states for Russound RIO (#130261)
This commit is contained in:
parent
f3229c723c
commit
d0dbca41f7
@ -96,6 +96,4 @@ class RussoundBaseEntity(Entity):
|
|||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Remove callbacks."""
|
"""Remove callbacks."""
|
||||||
await self._client.unregister_state_update_callbacks(
|
self._client.unregister_state_update_callbacks(self._state_update_callback)
|
||||||
self._state_update_callback
|
|
||||||
)
|
|
||||||
|
@ -132,7 +132,16 @@ class RussoundZoneDevice(RussoundBaseEntity, MediaPlayerEntity):
|
|||||||
def state(self) -> MediaPlayerState | None:
|
def state(self) -> MediaPlayerState | None:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
status = self._zone.status
|
status = self._zone.status
|
||||||
|
mode = self._source.mode
|
||||||
if status == "ON":
|
if status == "ON":
|
||||||
|
if mode == "playing":
|
||||||
|
return MediaPlayerState.PLAYING
|
||||||
|
if mode == "paused":
|
||||||
|
return MediaPlayerState.PAUSED
|
||||||
|
if mode == "transitioning":
|
||||||
|
return MediaPlayerState.BUFFERING
|
||||||
|
if mode == "stopped":
|
||||||
|
return MediaPlayerState.IDLE
|
||||||
return MediaPlayerState.ON
|
return MediaPlayerState.ON
|
||||||
if status == "OFF":
|
if status == "OFF":
|
||||||
return MediaPlayerState.OFF
|
return MediaPlayerState.OFF
|
||||||
|
@ -28,11 +28,9 @@ def mock_setup_entry():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Mock a Russound RIO config entry."""
|
"""Mock a Russound RIO config entry."""
|
||||||
entry = MockConfigEntry(
|
return MockConfigEntry(
|
||||||
domain=DOMAIN, data=MOCK_CONFIG, unique_id=HARDWARE_MAC, title=MODEL
|
domain=DOMAIN, data=MOCK_CONFIG, unique_id=HARDWARE_MAC, title=MODEL
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
|
||||||
return entry
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -70,4 +68,6 @@ def mock_russound_client() -> Generator[AsyncMock]:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
client.connection_handler = RussoundTcpConnectionHandler(HOST, PORT)
|
client.connection_handler = RussoundTcpConnectionHandler(HOST, PORT)
|
||||||
|
client.is_connected = Mock(return_value=True)
|
||||||
|
client.unregister_state_update_callbacks.return_value = True
|
||||||
yield client
|
yield client
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||||
|
|
||||||
HOST = "127.0.0.1"
|
HOST = "127.0.0.1"
|
||||||
PORT = 9621
|
PORT = 9621
|
||||||
MODEL = "MCA-C5"
|
MODEL = "MCA-C5"
|
||||||
@ -14,3 +16,7 @@ MOCK_CONFIG = {
|
|||||||
|
|
||||||
_CONTROLLER = namedtuple("Controller", ["mac_address", "controller_type"]) # noqa: PYI024
|
_CONTROLLER = namedtuple("Controller", ["mac_address", "controller_type"]) # noqa: PYI024
|
||||||
MOCK_CONTROLLERS = {1: _CONTROLLER(mac_address=HARDWARE_MAC, controller_type=MODEL)}
|
MOCK_CONTROLLERS = {1: _CONTROLLER(mac_address=HARDWARE_MAC, controller_type=MODEL)}
|
||||||
|
|
||||||
|
DEVICE_NAME = "mca_c5"
|
||||||
|
NAME_ZONE_1 = "backyard"
|
||||||
|
ENTITY_ID_ZONE_1 = f"{MP_DOMAIN}.{DEVICE_NAME}_{NAME_ZONE_1}"
|
||||||
|
58
tests/components/russound_rio/test_media_player.py
Normal file
58
tests/components/russound_rio/test_media_player.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
"""Tests for the Russound RIO media player."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from aiorussound.models import CallbackType
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.const import (
|
||||||
|
STATE_BUFFERING,
|
||||||
|
STATE_IDLE,
|
||||||
|
STATE_OFF,
|
||||||
|
STATE_ON,
|
||||||
|
STATE_PAUSED,
|
||||||
|
STATE_PLAYING,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import setup_integration
|
||||||
|
from .const import ENTITY_ID_ZONE_1
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def mock_state_update(client: AsyncMock) -> None:
|
||||||
|
"""Trigger a callback in the media player."""
|
||||||
|
for callback in client.register_state_update_callbacks.call_args_list:
|
||||||
|
await callback[0][0](client, CallbackType.STATE)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("zone_status", "source_mode", "media_player_state"),
|
||||||
|
[
|
||||||
|
("ON", None, STATE_ON),
|
||||||
|
("ON", "playing", STATE_PLAYING),
|
||||||
|
("ON", "paused", STATE_PAUSED),
|
||||||
|
("ON", "transitioning", STATE_BUFFERING),
|
||||||
|
("ON", "stopped", STATE_IDLE),
|
||||||
|
("OFF", None, STATE_OFF),
|
||||||
|
("OFF", "stopped", STATE_OFF),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_entity_state(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_russound_client: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
zone_status: str,
|
||||||
|
source_mode: str | None,
|
||||||
|
media_player_state: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test media player state."""
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
mock_russound_client.controllers[1].zones[1].status = zone_status
|
||||||
|
mock_russound_client.sources[1].mode = source_mode
|
||||||
|
await mock_state_update(mock_russound_client)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get(ENTITY_ID_ZONE_1)
|
||||||
|
assert state.state == media_player_state
|
Loading…
x
Reference in New Issue
Block a user