Sonos services to work without admin access (#31506)
parent
46fb73ea76
commit
6e0e58f6cc
|
@ -174,6 +174,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
|
||||
platform = entity_platform.current_platform.get()
|
||||
|
||||
@service.verify_domain_control(hass, SONOS_DOMAIN)
|
||||
async def async_service_handle(service_call: ServiceCall):
|
||||
"""Handle dispatched services."""
|
||||
entities = await platform.async_extract_from_service(service_call)
|
||||
|
@ -201,16 +202,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
hass, entities, service_call.data[ATTR_WITH_GROUP]
|
||||
)
|
||||
|
||||
service.async_register_admin_service(
|
||||
hass,
|
||||
hass.services.async_register(
|
||||
SONOS_DOMAIN,
|
||||
SERVICE_JOIN,
|
||||
async_service_handle,
|
||||
cv.make_entity_service_schema({vol.Required(ATTR_MASTER): cv.entity_id}),
|
||||
)
|
||||
|
||||
service.async_register_admin_service(
|
||||
hass,
|
||||
hass.services.async_register(
|
||||
SONOS_DOMAIN,
|
||||
SERVICE_UNJOIN,
|
||||
async_service_handle,
|
||||
|
@ -221,12 +220,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
{vol.Optional(ATTR_WITH_GROUP, default=True): cv.boolean}
|
||||
)
|
||||
|
||||
service.async_register_admin_service(
|
||||
hass, SONOS_DOMAIN, SERVICE_SNAPSHOT, async_service_handle, join_unjoin_schema
|
||||
hass.services.async_register(
|
||||
SONOS_DOMAIN, SERVICE_SNAPSHOT, async_service_handle, join_unjoin_schema
|
||||
)
|
||||
|
||||
service.async_register_admin_service(
|
||||
hass, SONOS_DOMAIN, SERVICE_RESTORE, async_service_handle, join_unjoin_schema
|
||||
hass.services.async_register(
|
||||
SONOS_DOMAIN, SERVICE_RESTORE, async_service_handle, join_unjoin_schema
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
|
|
|
@ -33,7 +33,7 @@ def soco_fixture(music_library, speaker_info, dummy_soco_service):
|
|||
yield mock_soco
|
||||
|
||||
|
||||
@pytest.fixture(name="discover")
|
||||
@pytest.fixture(name="discover", autouse=True)
|
||||
def discover_fixture(soco):
|
||||
"""Create a mock pysonos discover fixture."""
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
"""Tests for the Sonos Media Player platform."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.sonos import DOMAIN, media_player
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
|
@ -24,3 +28,17 @@ async def test_async_setup_entry_discover(hass, config_entry, discover):
|
|||
|
||||
entity = hass.data[media_player.DATA_SONOS].entities[0]
|
||||
assert entity.unique_id == "RINCON_test"
|
||||
|
||||
|
||||
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),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue