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:
Paulus Schoutsen 2016-04-04 12:18:58 -07:00
parent cbe9a7d2a3
commit 8ef542927f
24 changed files with 570 additions and 443 deletions

View file

@ -1,6 +1,7 @@
"""The tests for numeric state 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 TestAutomationNumericState(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.calls = []
def record_call(service):
@ -26,7 +28,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_fires_on_entity_change_below(self):
""""Test the firing with changed entity."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -37,7 +39,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 9)
self.hass.pool.block_till_done()
@ -48,7 +50,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.states.set('test.entity', 11)
self.hass.pool.block_till_done()
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -59,7 +61,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 9)
@ -71,7 +73,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.states.set('test.entity', 9)
self.hass.pool.block_till_done()
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -82,7 +84,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10 so this should not fire again
self.hass.states.set('test.entity', 8)
@ -91,7 +93,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_fires_on_entity_change_above(self):
""""Test the firing with changed entity."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -102,7 +104,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is above 10
self.hass.states.set('test.entity', 11)
self.hass.pool.block_till_done()
@ -114,7 +116,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.states.set('test.entity', 9)
self.hass.pool.block_till_done()
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -125,7 +127,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is above 10 and 9 is below
self.hass.states.set('test.entity', 11)
@ -138,7 +140,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.states.set('test.entity', 11)
self.hass.pool.block_till_done()
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -149,7 +151,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is above 10 so this should fire again
self.hass.states.set('test.entity', 12)
@ -158,7 +160,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_fires_on_entity_change_below_range(self):
""""Test the firing with changed entity."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -170,7 +172,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 9)
self.hass.pool.block_till_done()
@ -178,7 +180,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_fires_on_entity_change_below_above_range(self):
""""Test the firing with changed entity."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -190,7 +192,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 4 is below 5
self.hass.states.set('test.entity', 4)
self.hass.pool.block_till_done()
@ -201,7 +203,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.states.set('test.entity', 11)
self.hass.pool.block_till_done()
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -213,7 +215,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 9)
@ -225,7 +227,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.states.set('test.entity', 11)
self.hass.pool.block_till_done()
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -237,7 +239,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 4 is below 5 so it should not fire
self.hass.states.set('test.entity', 4)
@ -246,7 +248,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_not_fires_if_entity_not_match(self):
""""Test if not fired with non matching entity."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -256,7 +258,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
self.hass.states.set('test.entity', 11)
self.hass.pool.block_till_done()
@ -264,7 +266,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_fires_on_entity_change_below_with_attribute(self):
""""Test attributes change."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -275,7 +277,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 9, {'test_attribute': 11})
self.hass.pool.block_till_done()
@ -283,7 +285,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_not_fires_on_entity_change_not_below_with_attribute(self):
""""Test attributes."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -294,7 +296,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is not below 10
self.hass.states.set('test.entity', 11, {'test_attribute': 9})
self.hass.pool.block_till_done()
@ -302,7 +304,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_fires_on_attribute_change_with_attribute_below(self):
""""Test attributes change."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -314,7 +316,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9})
self.hass.pool.block_till_done()
@ -322,7 +324,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_not_fires_on_attribute_change_with_attribute_not_below(self):
""""Test attributes change."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -334,7 +336,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is not below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11})
self.hass.pool.block_till_done()
@ -342,7 +344,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_not_fires_on_entity_change_with_attribute_below(self):
""""Test attributes change."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -354,7 +356,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is not below 10, entity state value should not be tested
self.hass.states.set('test.entity', '9', {'test_attribute': 11})
self.hass.pool.block_till_done()
@ -362,7 +364,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_if_not_fires_on_entity_change_with_not_attribute_below(self):
""""Test attributes change."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -374,7 +376,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is not below 10, entity state value should not be tested
self.hass.states.set('test.entity', 'entity')
self.hass.pool.block_till_done()
@ -382,7 +384,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(self):
""""Test attributes change."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -394,7 +396,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is not below 10
self.hass.states.set('test.entity', 'entity',
{'test_attribute': 9, 'not_test_attribute': 11})
@ -403,7 +405,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_template_list(self):
""""Test template list."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -416,7 +418,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 3 is below 10
self.hass.states.set('test.entity', 'entity',
{'test_attribute': [11, 15, 3]})
@ -425,7 +427,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_template_string(self):
""""Test template string."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -438,7 +440,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 9 is below 10
self.hass.states.set('test.entity', 'entity',
{'test_attribute': '0.9'})
@ -447,7 +449,7 @@ class TestAutomationNumericState(unittest.TestCase):
def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(self):
""""Test if not fired changed attributes."""
self.assertTrue(automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
@ -459,7 +461,7 @@ class TestAutomationNumericState(unittest.TestCase):
'service': 'test.automation'
}
}
}))
})
# 11 is not below 10
self.hass.states.set('test.entity', 'entity',
{'test_attribute': 11, 'not_test_attribute': 9})
@ -470,7 +472,7 @@ class TestAutomationNumericState(unittest.TestCase):
""""Test if action."""
entity_id = 'domain.test_entity'
test_state = 10
automation.setup(self.hass, {
assert _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',