2019-04-26 06:56:43 +00:00
|
|
|
"""Tests for the Sonos Media Player platform."""
|
2020-02-05 23:50:20 +00:00
|
|
|
import pytest
|
|
|
|
|
2019-10-19 21:52:42 +00:00
|
|
|
from homeassistant.components.sonos import DOMAIN, media_player
|
2020-02-05 23:50:20 +00:00
|
|
|
from homeassistant.core import Context
|
|
|
|
from homeassistant.exceptions import Unauthorized
|
2019-04-26 06:56:43 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2016-07-29 03:40:58 +00:00
|
|
|
|
|
|
|
|
2019-04-26 06:56:43 +00:00
|
|
|
async def setup_platform(hass, config_entry, config):
|
|
|
|
"""Set up the media player platform for testing."""
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
assert await async_setup_component(hass, DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
2016-07-29 03:40:58 +00:00
|
|
|
|
|
|
|
|
2019-04-26 06:56:43 +00:00
|
|
|
async def test_async_setup_entry_hosts(hass, config_entry, config, soco):
|
|
|
|
"""Test static setup."""
|
|
|
|
await setup_platform(hass, config_entry, config)
|
2019-04-29 08:20:09 +00:00
|
|
|
|
|
|
|
entity = hass.data[media_player.DATA_SONOS].entities[0]
|
|
|
|
assert entity.soco == soco
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2016-07-30 08:30:13 +00:00
|
|
|
|
2019-04-26 06:56:43 +00:00
|
|
|
async def test_async_setup_entry_discover(hass, config_entry, discover):
|
|
|
|
"""Test discovery setup."""
|
|
|
|
await setup_platform(hass, config_entry, {})
|
2019-04-29 08:20:09 +00:00
|
|
|
|
|
|
|
entity = hass.data[media_player.DATA_SONOS].entities[0]
|
2019-07-31 19:25:30 +00:00
|
|
|
assert entity.unique_id == "RINCON_test"
|
2020-02-05 23:50:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_services(hass, config_entry, config, hass_read_only_user):
|
|
|
|
"""Test join/unjoin requires control access."""
|
|
|
|
await setup_platform(hass, config_entry, config)
|
|
|
|
|
|
|
|
with pytest.raises(Unauthorized):
|
|
|
|
await hass.services.async_call(
|
|
|
|
DOMAIN,
|
|
|
|
media_player.SERVICE_JOIN,
|
|
|
|
{"master": "media_player.bla", "entity_id": "media_player.blub"},
|
|
|
|
blocking=True,
|
|
|
|
context=Context(user_id=hass_read_only_user.id),
|
|
|
|
)
|