mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Admin service to automatically add empty schema (#22637)
* Admin service to automatically add empty schema * Lint
This commit is contained in:
parent
b8b3f4e88f
commit
e00ae35e07
@ -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(
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user