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
|
@ -44,6 +44,32 @@ class TestConditionHelper:
|
|||
self.hass.states.set('sensor.temperature', 100)
|
||||
assert test(self.hass)
|
||||
|
||||
def test_and_condition_with_template(self):
|
||||
"""Test the 'and' condition."""
|
||||
test = condition.from_config({
|
||||
'condition': 'and',
|
||||
'conditions': [
|
||||
{
|
||||
'condition': 'template',
|
||||
'value_template':
|
||||
'{{ states.sensor.temperature.state == "100" }}',
|
||||
}, {
|
||||
'condition': 'numeric_state',
|
||||
'entity_id': 'sensor.temperature',
|
||||
'below': 110,
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
self.hass.states.set('sensor.temperature', 120)
|
||||
assert not test(self.hass)
|
||||
|
||||
self.hass.states.set('sensor.temperature', 105)
|
||||
assert not test(self.hass)
|
||||
|
||||
self.hass.states.set('sensor.temperature', 100)
|
||||
assert test(self.hass)
|
||||
|
||||
def test_or_condition(self):
|
||||
"""Test the 'or' condition."""
|
||||
test = condition.from_config({
|
||||
|
@ -70,6 +96,32 @@ class TestConditionHelper:
|
|||
self.hass.states.set('sensor.temperature', 100)
|
||||
assert test(self.hass)
|
||||
|
||||
def test_or_condition_with_template(self):
|
||||
"""Test the 'or' condition."""
|
||||
test = condition.from_config({
|
||||
'condition': 'or',
|
||||
'conditions': [
|
||||
{
|
||||
'condition': 'template',
|
||||
'value_template':
|
||||
'{{ states.sensor.temperature.state == "100" }}',
|
||||
}, {
|
||||
'condition': 'numeric_state',
|
||||
'entity_id': 'sensor.temperature',
|
||||
'below': 110,
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
self.hass.states.set('sensor.temperature', 120)
|
||||
assert not test(self.hass)
|
||||
|
||||
self.hass.states.set('sensor.temperature', 105)
|
||||
assert test(self.hass)
|
||||
|
||||
self.hass.states.set('sensor.temperature', 100)
|
||||
assert test(self.hass)
|
||||
|
||||
def test_time_window(self):
|
||||
"""Test time condition windows."""
|
||||
sixam = dt.parse_time("06:00:00")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue