diff --git a/homeassistant/components/cloud/__init__.py b/homeassistant/components/cloud/__init__.py index fca5b292033..41045ba1f91 100644 --- a/homeassistant/components/cloud/__init__.py +++ b/homeassistant/components/cloud/__init__.py @@ -187,11 +187,10 @@ async def async_setup(hass, config): await cloud.remote.disconnect() await prefs.async_update(remote_enabled=False) - empty_schema = vol.Schema({}) hass.helpers.service.async_register_admin_service( - DOMAIN, SERVICE_REMOTE_CONNECT, _service_handler, empty_schema) + DOMAIN, SERVICE_REMOTE_CONNECT, _service_handler) hass.helpers.service.async_register_admin_service( - DOMAIN, SERVICE_REMOTE_DISCONNECT, _service_handler, empty_schema) + DOMAIN, SERVICE_REMOTE_DISCONNECT, _service_handler) await http_api.async_setup(hass) hass.async_create_task(hass.helpers.discovery.async_load_platform( diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index f8af3bdb1c5..3892dbb6607 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -333,9 +333,10 @@ async def _handle_service_platform_call(func, data, entities, context): @bind_hass @ha.callback -def async_register_admin_service(hass: typing.HomeAssistantType, domain: str, - service: str, service_func: Callable, - schema: vol.Schema) -> None: +def async_register_admin_service( + hass: typing.HomeAssistantType, domain: str, + service: str, service_func: Callable, + schema: vol.Schema = vol.Schema({}, extra=vol.PREVENT_EXTRA)) -> None: """Register a service that requires admin access.""" @wraps(service_func) async def admin_handler(call): diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index a36785b6ba0..f59a01ec268 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -406,7 +406,11 @@ async def test_register_admin_service(hass, hass_read_only_user, calls.append(call) hass.helpers.service.async_register_admin_service( - 'test', 'test', mock_service, vol.Schema({}) + 'test', 'test', mock_service + ) + hass.helpers.service.async_register_admin_service( + 'test', 'test2', mock_service, + vol.Schema({vol.Required('required'): cv.boolean}) ) with pytest.raises(exceptions.UnknownUser): @@ -423,8 +427,21 @@ async def test_register_admin_service(hass, hass_read_only_user, )) assert len(calls) == 0 + with pytest.raises(vol.Invalid): + await hass.services.async_call( + 'test', 'test', {'invalid': True}, blocking=True, + context=ha.Context(user_id=hass_admin_user.id)) + assert len(calls) == 0 + + with pytest.raises(vol.Invalid): + await hass.services.async_call( + 'test', 'test2', {}, blocking=True, context=ha.Context( + user_id=hass_admin_user.id + )) + assert len(calls) == 0 + await hass.services.async_call( - 'test', 'test', {}, blocking=True, context=ha.Context( + 'test', 'test2', {'required': True}, blocking=True, context=ha.Context( user_id=hass_admin_user.id )) assert len(calls) == 1