mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add test for delay on automations (#4630)
This commit is contained in:
parent
6ddbb4d568
commit
66473120ab
@ -1,5 +1,6 @@
|
|||||||
"""The tests for the automation component."""
|
"""The tests for the automation component."""
|
||||||
import unittest
|
import unittest
|
||||||
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -9,7 +10,8 @@ from homeassistant.const import ATTR_ENTITY_ID
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant, assert_setup_component
|
from tests.common import get_test_home_assistant, assert_setup_component, \
|
||||||
|
fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
class TestAutomation(unittest.TestCase):
|
class TestAutomation(unittest.TestCase):
|
||||||
@ -85,6 +87,59 @@ class TestAutomation(unittest.TestCase):
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.attributes.get('entity_id') == ('automation.hello',)
|
assert state.attributes.get('entity_id') == ('automation.hello',)
|
||||||
|
|
||||||
|
def test_action_delay(self):
|
||||||
|
"""Test action delay."""
|
||||||
|
assert setup_component(self.hass, automation.DOMAIN, {
|
||||||
|
automation.DOMAIN: {
|
||||||
|
'alias': 'hello',
|
||||||
|
'trigger': {
|
||||||
|
'platform': 'event',
|
||||||
|
'event_type': 'test_event',
|
||||||
|
},
|
||||||
|
'action': [
|
||||||
|
{
|
||||||
|
'service': 'test.automation',
|
||||||
|
'data_template': {
|
||||||
|
'some': '{{ trigger.platform }} - '
|
||||||
|
'{{ trigger.event.event_type }}'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{'delay': {'minutes': '10'}},
|
||||||
|
{
|
||||||
|
'service': 'test.automation',
|
||||||
|
'data_template': {
|
||||||
|
'some': '{{ trigger.platform }} - '
|
||||||
|
'{{ trigger.event.event_type }}'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
time = dt_util.utcnow()
|
||||||
|
|
||||||
|
with patch('homeassistant.components.automation.utcnow',
|
||||||
|
return_value=time):
|
||||||
|
self.hass.bus.fire('test_event')
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
|
assert len(self.calls) == 1
|
||||||
|
assert self.calls[0].data['some'] == 'event - test_event'
|
||||||
|
|
||||||
|
future = dt_util.utcnow() + timedelta(minutes=10)
|
||||||
|
fire_time_changed(self.hass, future)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
|
assert len(self.calls) == 2
|
||||||
|
assert self.calls[1].data['some'] == 'event - test_event'
|
||||||
|
|
||||||
|
state = self.hass.states.get('automation.hello')
|
||||||
|
assert state is not None
|
||||||
|
assert state.attributes.get('last_triggered') == time
|
||||||
|
state = self.hass.states.get('group.all_automations')
|
||||||
|
assert state is not None
|
||||||
|
assert state.attributes.get('entity_id') == ('automation.hello',)
|
||||||
|
|
||||||
def test_service_specify_entity_id(self):
|
def test_service_specify_entity_id(self):
|
||||||
"""Test service data."""
|
"""Test service data."""
|
||||||
assert setup_component(self.hass, automation.DOMAIN, {
|
assert setup_component(self.hass, automation.DOMAIN, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user