From 5bd58351c70af99ec36d82bf768ff6b7a9e2f2b9 Mon Sep 17 00:00:00 2001 From: Jan Harkes Date: Thu, 31 Mar 2016 15:04:50 -0400 Subject: [PATCH] Move service scheme validation into Service.__call__ Keeps where the schema is stored and validated close. --- homeassistant/core.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 208c5d3438b..f82bfd7b244 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -514,7 +514,14 @@ class Service(object): def __call__(self, call): """Execute the service.""" - self.func(call) + try: + if self.schema: + call.data = self.schema(call.data) + + 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 @@ -642,15 +649,6 @@ class ServiceRegistry(object): return 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) # Add a job to the pool that calls _execute_service