From 12b5caed70721b3f924b316239627cbba81021be Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 9 Jan 2016 15:51:51 -0800 Subject: [PATCH] ps - strip entity IDs in service call --- homeassistant/helpers/service.py | 3 ++- tests/helpers/test_service.py | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/helpers/test_service.py diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 632b3d39cbb..530f72fa22f 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -30,7 +30,8 @@ def call_from_config(hass, config, blocking=False): entity_id = config.get(CONF_SERVICE_ENTITY_ID) if isinstance(entity_id, str): - service_data[ATTR_ENTITY_ID] = entity_id.split(",") + service_data[ATTR_ENTITY_ID] = [ent.strip() for ent in + entity_id.split(",")] elif entity_id is not None: service_data[ATTR_ENTITY_ID] = entity_id diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py new file mode 100644 index 00000000000..32a36edc5f1 --- /dev/null +++ b/tests/helpers/test_service.py @@ -0,0 +1,39 @@ +""" +tests.helpers.test_service +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Test service helpers. +""" +from datetime import timedelta +import unittest +from unittest.mock import patch + +import homeassistant.core as ha +from homeassistant.const import SERVICE_TURN_ON +from homeassistant.helpers import service + +from tests.common import get_test_home_assistant, mock_service + + +class TestServiceHelpers(unittest.TestCase): + """ + Tests the Home Assistant service helpers. + """ + + def setUp(self): # pylint: disable=invalid-name + """ things to be run when tests are started. """ + self.hass = get_test_home_assistant() + self.calls = mock_service(self.hass, 'test_domain', 'test_service') + + def tearDown(self): # pylint: disable=invalid-name + """ Stop down stuff we started. """ + self.hass.stop() + + def test_split_entity_string(self): + service.call_from_config(self.hass, { + 'service': 'test_domain.test_service', + 'entity_id': 'hello.world, sensor.beer' + }) + self.hass.pool.block_till_done() + self.assertEqual(['hello.world', 'sensor.beer'], + self.calls[-1].data.get('entity_id'))