mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add automation config validation
* Add automation config validation * Remove unnecessary dict validator * Downgrade voluptuous to 0.8.9 * Fix linting * Address issues
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""The tests fr the Template automation."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
import homeassistant.components.automation as automation
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
@@ -12,6 +13,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
self.calls = []
|
||||
|
||||
@@ -27,7 +29,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_bool(self):
|
||||
"""Test for firing on boolean change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -37,7 +39,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -45,7 +47,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_str(self):
|
||||
"""Test for firing on change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -55,7 +57,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -63,7 +65,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_str_crazy(self):
|
||||
"""Test for firing on change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -73,7 +75,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -81,7 +83,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_not_fires_on_change_bool(self):
|
||||
"""Test for not firing on boolean change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -91,7 +93,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -99,7 +101,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_not_fires_on_change_str(self):
|
||||
"""Test for not firing on string change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -109,7 +111,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -117,7 +119,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_not_fires_on_change_str_crazy(self):
|
||||
"""Test for not firing on string change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -127,7 +129,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -135,7 +137,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_no_change(self):
|
||||
"""Test for firing on no change."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -145,7 +147,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -153,7 +155,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_two_change(self):
|
||||
"""Test for firing on two changes."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -163,7 +165,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
# Trigger once
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
@@ -177,7 +179,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_with_template(self):
|
||||
"""Test for firing on change with template."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -187,7 +189,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -195,7 +197,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_not_fires_on_change_with_template(self):
|
||||
"""Test for not firing on change with template."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -205,7 +207,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -213,7 +215,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_with_template_advanced(self):
|
||||
"""Test for firing on change with template advanced."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -227,7 +229,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -235,7 +237,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_no_change_with_template_advanced(self):
|
||||
"""Test for firing on no change with template advanced."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -249,7 +251,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
# Different state
|
||||
self.hass.states.set('test.entity', 'worldz')
|
||||
@@ -263,7 +265,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_with_template_2(self):
|
||||
"""Test for firing on change with template."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -274,7 +276,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
@@ -302,7 +304,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_action(self):
|
||||
"""Test for firing if action."""
|
||||
automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'event',
|
||||
@@ -335,7 +337,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
def test_if_fires_on_change_with_bad_template(self):
|
||||
"""Test for firing on change with bad template."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert not _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -345,15 +347,11 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
})
|
||||
|
||||
def test_if_fires_on_change_with_bad_template_2(self):
|
||||
"""Test for firing on change with bad template."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
'trigger': {
|
||||
'platform': 'template',
|
||||
@@ -363,7 +361,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
'service': 'test.automation'
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
Reference in New Issue
Block a user