From f5030d9ebf025d82690fa752814857f8d8ec9db5 Mon Sep 17 00:00:00 2001 From: Tod Schmidt Date: Mon, 5 Feb 2018 03:19:56 -0500 Subject: [PATCH] Services (small_pr)(fix): Added missing return on data template error (#12184) * Added return on data template error * Rebased so not sure why spelling errors returned... --- homeassistant/helpers/service.py | 1 + tests/helpers/test_service.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index f5b626c8828..b89b1689c9e 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -74,6 +74,7 @@ def async_call_from_config(hass, config, blocking=False, variables=None, config[CONF_SERVICE_DATA_TEMPLATE], variables)) except TemplateError as ex: _LOGGER.error('Error rendering data template: %s', ex) + return if CONF_SERVICE_ENTITY_ID in config: service_data[ATTR_ENTITY_ID] = config[CONF_SERVICE_ENTITY_ID] diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index a5bd6798084..a987f5130f1 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -68,6 +68,24 @@ class TestServiceHelpers(unittest.TestCase): self.assertEqual('goodbye', self.calls[0].data['hello']) + def test_bad_template(self): + """Test passing bad template.""" + config = { + 'service_template': '{{ var_service }}', + 'entity_id': 'hello.world', + 'data_template': { + 'hello': '{{ states + unknown_var }}' + } + } + + service.call_from_config(self.hass, config, variables={ + 'var_service': 'test_domain.test_service', + 'var_data': 'goodbye', + }) + self.hass.block_till_done() + + self.assertEqual(len(self.calls), 0) + def test_split_entity_string(self): """Test splitting of entity string.""" service.call_from_config(self.hass, {