Use templates in service calls
This commit is contained in:
parent
cfd65e48cb
commit
81e5a852f0
3 changed files with 78 additions and 8 deletions
|
@ -39,6 +39,25 @@ class TestServiceHelpers(unittest.TestCase):
|
|||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(runs))
|
||||
|
||||
def test_template_service_call(self):
|
||||
""" Test service call with tempating. """
|
||||
config = {
|
||||
'service_template': '{{ \'test_domain.test_service\' }}',
|
||||
'entity_id': 'hello.world',
|
||||
'data_template': {
|
||||
'hello': '{{ \'goodbye\' }}',
|
||||
},
|
||||
}
|
||||
runs = []
|
||||
|
||||
decor = service.service('test_domain', 'test_service')
|
||||
decor(lambda x, y: runs.append(y))
|
||||
|
||||
service.call_from_config(self.hass, config)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual('goodbye', runs[0].data['hello'])
|
||||
|
||||
def test_split_entity_string(self):
|
||||
service.call_from_config(self.hass, {
|
||||
'service': 'test_domain.test_service',
|
||||
|
@ -99,3 +118,21 @@ class TestServiceHelpers(unittest.TestCase):
|
|||
|
||||
self.assertEqual(['light.ceiling', 'light.kitchen'],
|
||||
service.extract_entity_ids(self.hass, call))
|
||||
|
||||
def test_validate_service_call(self):
|
||||
"""Test is_valid_service_call method"""
|
||||
self.assertNotEqual(
|
||||
service.validate_service_call(
|
||||
{}),
|
||||
None
|
||||
)
|
||||
self.assertEqual(
|
||||
service.validate_service_call(
|
||||
{'service': 'test_domain.test_service'}),
|
||||
None
|
||||
)
|
||||
self.assertEqual(
|
||||
service.validate_service_call(
|
||||
{'service_template': 'test_domain.{{ \'test_service\' }}'}),
|
||||
None
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue