mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Remove support for old deprecated automation config
This commit is contained in:
@@ -5,8 +5,6 @@ from unittest.mock import patch
|
||||
|
||||
import homeassistant.util.dt as dt_util
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.automation import time, event
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
|
||||
from tests.common import fire_time_changed, get_test_home_assistant
|
||||
|
||||
@@ -28,207 +26,6 @@ class TestAutomationTime(unittest.TestCase):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_old_config_if_fires_when_hour_matches(self):
|
||||
"""Test for firing if hours are matching."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
'platform': 'time',
|
||||
time.CONF_HOURS: 0,
|
||||
'execute_service': 'test.automation'
|
||||
}
|
||||
}))
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_fires_when_minute_matches(self):
|
||||
"""Test for firing if minutes are matching."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
'platform': 'time',
|
||||
time.CONF_MINUTES: 0,
|
||||
'execute_service': 'test.automation'
|
||||
}
|
||||
}))
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow().replace(minute=0))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_fires_when_second_matches(self):
|
||||
"""Test for firing if seconds are matching."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
'platform': 'time',
|
||||
time.CONF_SECONDS: 0,
|
||||
'execute_service': 'test.automation'
|
||||
}
|
||||
}))
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_fires_when_all_matches(self):
|
||||
"""Test for firing if everything matches."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'time',
|
||||
time.CONF_HOURS: 0,
|
||||
time.CONF_MINUTES: 0,
|
||||
time.CONF_SECONDS: 0,
|
||||
'execute_service': 'test.automation'
|
||||
}
|
||||
}))
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow().replace(
|
||||
hour=0, minute=0, second=0))
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_action_before(self):
|
||||
"""Test for action before."""
|
||||
automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'event',
|
||||
event.CONF_EVENT_TYPE: 'test_event',
|
||||
'execute_service': 'test.automation',
|
||||
'if': {
|
||||
CONF_PLATFORM: 'time',
|
||||
time.CONF_BEFORE: '10:00'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
before_10 = dt_util.now().replace(hour=8)
|
||||
after_10 = dt_util.now().replace(hour=14)
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=before_10):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=after_10):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_action_after(self):
|
||||
"""Test for action after."""
|
||||
automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'event',
|
||||
event.CONF_EVENT_TYPE: 'test_event',
|
||||
'execute_service': 'test.automation',
|
||||
'if': {
|
||||
CONF_PLATFORM: 'time',
|
||||
time.CONF_AFTER: '10:00'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
before_10 = dt_util.now().replace(hour=8)
|
||||
after_10 = dt_util.now().replace(hour=14)
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=before_10):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=after_10):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_action_one_weekday(self):
|
||||
"""Test for action with one weekday."""
|
||||
automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'event',
|
||||
event.CONF_EVENT_TYPE: 'test_event',
|
||||
'execute_service': 'test.automation',
|
||||
'if': {
|
||||
CONF_PLATFORM: 'time',
|
||||
time.CONF_WEEKDAY: 'mon',
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
days_past_monday = dt_util.now().weekday()
|
||||
monday = dt_util.now() - timedelta(days=days_past_monday)
|
||||
tuesday = monday + timedelta(days=1)
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=monday):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=tuesday):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_old_config_if_action_list_weekday(self):
|
||||
"""Test for action with a list of weekdays."""
|
||||
automation.setup(self.hass, {
|
||||
automation.DOMAIN: {
|
||||
CONF_PLATFORM: 'event',
|
||||
event.CONF_EVENT_TYPE: 'test_event',
|
||||
'execute_service': 'test.automation',
|
||||
'if': {
|
||||
CONF_PLATFORM: 'time',
|
||||
time.CONF_WEEKDAY: ['mon', 'tue'],
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
days_past_monday = dt_util.now().weekday()
|
||||
monday = dt_util.now() - timedelta(days=days_past_monday)
|
||||
tuesday = monday + timedelta(days=1)
|
||||
wednesday = tuesday + timedelta(days=1)
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=monday):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=tuesday):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(2, len(self.calls))
|
||||
|
||||
with patch('homeassistant.components.automation.time.dt_util.now',
|
||||
return_value=wednesday):
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(2, len(self.calls))
|
||||
|
||||
def test_if_fires_when_hour_matches(self):
|
||||
"""Test for firing if hour is matching."""
|
||||
self.assertTrue(automation.setup(self.hass, {
|
||||
|
||||
Reference in New Issue
Block a user