mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move service scheme validation into Service.__call__
Keeps where the schema is stored and validated close.
This commit is contained in:
parent
64030b9d48
commit
5bd58351c7
@ -514,7 +514,14 @@ class Service(object):
|
|||||||
|
|
||||||
def __call__(self, call):
|
def __call__(self, call):
|
||||||
"""Execute the service."""
|
"""Execute the service."""
|
||||||
|
try:
|
||||||
|
if self.schema:
|
||||||
|
call.data = self.schema(call.data)
|
||||||
|
|
||||||
self.func(call)
|
self.func(call)
|
||||||
|
except vol.MultipleInvalid as ex:
|
||||||
|
_LOGGER.error('Invalid service data for %s.%s: %s',
|
||||||
|
call.domain, call.service, ex)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@ -642,15 +649,6 @@ class ServiceRegistry(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
service_handler = self._services[domain][service]
|
service_handler = self._services[domain][service]
|
||||||
service_validator = service_handler.schema
|
|
||||||
try:
|
|
||||||
if service_validator:
|
|
||||||
service_data = service_validator(service_data)
|
|
||||||
except vol.MultipleInvalid as ex:
|
|
||||||
_LOGGER.error('Invalid service data for %s.%s: %s',
|
|
||||||
domain, service, ex)
|
|
||||||
return
|
|
||||||
|
|
||||||
service_call = ServiceCall(domain, service, service_data, call_id)
|
service_call = ServiceCall(domain, service, service_data, call_id)
|
||||||
|
|
||||||
# Add a job to the pool that calls _execute_service
|
# Add a job to the pool that calls _execute_service
|
||||||
|
Loading…
x
Reference in New Issue
Block a user