Optimize template 2 (#3521)
* Enforce compiling templates * Refactor templates * Add template validator to Logbook service * Some more fixes * Lint * Allow easy skipping of rfxtrx tests * Fix template bug in AND & OR conditions * add entities extractor Conflicts: tests/helpers/test_template.py * fix unittest * Convert template to be async * Fix Farcy * Lint fix * Limit template updates to related entities * Make template automation async
This commit is contained in:
parent
6694b0470e
commit
00e298206e
52 changed files with 841 additions and 562 deletions
|
@ -6,7 +6,7 @@ import unittest
|
|||
# Otherwise can't test just this file (import order issue)
|
||||
import homeassistant.components # noqa
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.helpers import script
|
||||
from homeassistant.helpers import script, config_validation as cv
|
||||
|
||||
from tests.common import fire_time_changed, get_test_home_assistant
|
||||
|
||||
|
@ -36,12 +36,12 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
script_obj = script.Script(self.hass, {
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA({
|
||||
'event': event,
|
||||
'event_data': {
|
||||
'hello': 'world'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
script_obj.run()
|
||||
|
||||
|
@ -61,14 +61,13 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.services.register('test', 'script', record_call)
|
||||
|
||||
script_obj = script.Script(self.hass, {
|
||||
script.call_from_config(self.hass, {
|
||||
'service': 'test.script',
|
||||
'data': {
|
||||
'hello': 'world'
|
||||
}
|
||||
})
|
||||
|
||||
script_obj.run()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
|
@ -84,7 +83,7 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.services.register('test', 'script', record_call)
|
||||
|
||||
script_obj = script.Script(self.hass, {
|
||||
script.call_from_config(self.hass, {
|
||||
'service_template': """
|
||||
{% if True %}
|
||||
test.script
|
||||
|
@ -102,8 +101,6 @@ class TestScriptHelper(unittest.TestCase):
|
|||
}
|
||||
})
|
||||
|
||||
script_obj.run()
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
|
@ -120,10 +117,10 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
script_obj = script.Script(self.hass, [
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||
{'event': event},
|
||||
{'delay': {'seconds': 5}},
|
||||
{'event': event}])
|
||||
{'event': event}]))
|
||||
|
||||
script_obj.run()
|
||||
|
||||
|
@ -152,10 +149,10 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
script_obj = script.Script(self.hass, [
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||
{'event': event},
|
||||
{'delay': '00:00:{{ 5 }}'},
|
||||
{'event': event}])
|
||||
{'event': event}]))
|
||||
|
||||
script_obj.run()
|
||||
|
||||
|
@ -184,9 +181,9 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
script_obj = script.Script(self.hass, [
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||
{'delay': {'seconds': 5}},
|
||||
{'event': event}])
|
||||
{'event': event}]))
|
||||
|
||||
script_obj.run()
|
||||
|
||||
|
@ -217,7 +214,7 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.services.register('test', 'script', record_call)
|
||||
|
||||
script_obj = script.Script(self.hass, [
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||
{
|
||||
'service': 'test.script',
|
||||
'data_template': {
|
||||
|
@ -230,7 +227,7 @@ class TestScriptHelper(unittest.TestCase):
|
|||
'data_template': {
|
||||
'hello': '{{ greeting2 }}',
|
||||
},
|
||||
}])
|
||||
}]))
|
||||
|
||||
script_obj.run({
|
||||
'greeting': 'world',
|
||||
|
@ -264,14 +261,14 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
|
||||
script_obj = script.Script(self.hass, [
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||
{'event': event},
|
||||
{
|
||||
'condition': 'template',
|
||||
'value_template': '{{ states.test.entity.state == "hello" }}',
|
||||
},
|
||||
{'event': event},
|
||||
])
|
||||
]))
|
||||
|
||||
script_obj.run()
|
||||
self.hass.block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue