Add automation mqtt tests
This commit is contained in:
parent
eecc51c92d
commit
291cc62381
7 changed files with 228 additions and 34 deletions
|
@ -7,7 +7,6 @@ Tests demo component.
|
|||
import unittest
|
||||
|
||||
import homeassistant as ha
|
||||
import homeassistant.loader as loader
|
||||
import homeassistant.components.automation as automation
|
||||
import homeassistant.components.automation.state as state
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
|
@ -18,7 +17,6 @@ class TestAutomationState(unittest.TestCase):
|
|||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
self.hass = ha.HomeAssistant()
|
||||
loader.prepare(self.hass)
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
self.calls = []
|
||||
|
||||
|
@ -31,49 +29,57 @@ class TestAutomationState(unittest.TestCase):
|
|||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_fails_if_no_entity_id(self):
|
||||
self.assertFalse(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
}))
|
||||
|
||||
def test_if_fires_on_entity_change(self):
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.entity',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_with_from_filter(self):
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.entity',
|
||||
state.CONF_FROM: 'hello',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_with_to_filter(self):
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.entity',
|
||||
state.CONF_TO: 'world',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_with_both_filters(self):
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.entity',
|
||||
|
@ -81,14 +87,14 @@ class TestAutomationState(unittest.TestCase):
|
|||
state.CONF_TO: 'world',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_if_to_filter_not_match(self):
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.entity',
|
||||
|
@ -96,7 +102,7 @@ class TestAutomationState(unittest.TestCase):
|
|||
state.CONF_TO: 'world',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'moon')
|
||||
self.hass.pool.block_till_done()
|
||||
|
@ -105,7 +111,7 @@ class TestAutomationState(unittest.TestCase):
|
|||
def test_if_not_fires_if_from_filter_not_match(self):
|
||||
self.hass.states.set('test.entity', 'bye')
|
||||
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.entity',
|
||||
|
@ -113,20 +119,20 @@ class TestAutomationState(unittest.TestCase):
|
|||
state.CONF_TO: 'world',
|
||||
automation.CONF_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_not_fires_if_entity_not_match(self):
|
||||
automation.setup(self.hass, {
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'state',
|
||||
state.CONF_ENTITY_ID: 'test.another_entity',
|
||||
automation.CONF_SERVICE: 'test.automation'
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue