Split time_pattern triggers from time trigger (#19825)

* Split interval triggers from time trigger

* Default smaller interval units to zero

* Rename interval to schedule

* Rename schedule to time_pattern
This commit is contained in:
Adam Mills 2019-01-15 12:33:34 -05:00 committed by Paulus Schoutsen
parent 5b53bd6aa0
commit 336b6adc88
4 changed files with 277 additions and 191 deletions

View file

@ -10,7 +10,6 @@ import homeassistant.components.automation as automation
from tests.common import (
async_fire_time_changed, assert_setup_component, mock_component)
from tests.components.automation import common
from tests.common import async_mock_service
@ -26,158 +25,6 @@ def setup_comp(hass):
mock_component(hass, 'group')
async def test_if_fires_when_hour_matches(hass, calls):
"""Test for firing if hour is matching."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'hours': 0,
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done()
assert 1 == len(calls)
await common.async_turn_off(hass)
await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_when_minute_matches(hass, calls):
"""Test for firing if minutes are matching."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'minutes': 0,
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(minute=0))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_when_second_matches(hass, calls):
"""Test for firing if seconds are matching."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'seconds': 0,
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(second=0))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_when_all_matches(hass, calls):
"""Test for firing if everything matches."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'hours': 1,
'minutes': 2,
'seconds': 3,
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=1, minute=2, second=3))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_periodic_seconds(hass, calls):
"""Test for firing periodically every second."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'seconds': "/2",
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=0, minute=0, second=2))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_periodic_minutes(hass, calls):
"""Test for firing periodically every minute."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'minutes': "/2",
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=0, minute=2, second=0))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_periodic_hours(hass, calls):
"""Test for firing periodically every hour."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'hours': "/2",
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=2, minute=0, second=0))
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_using_at(hass, calls):
"""Test for firing at."""
assert await async_setup_component(hass, automation.DOMAIN, {
@ -204,27 +51,6 @@ async def test_if_fires_using_at(hass, calls):
assert 'time - 5' == calls[0].data['some']
async def test_if_not_working_if_no_values_in_conf_provided(hass, calls):
"""Test for failure if no configuration."""
with assert_setup_component(0):
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=5, minute=0, second=0))
await hass.async_block_till_done()
assert 0 == len(calls)
async def test_if_not_fires_using_wrong_at(hass, calls):
"""YAML translates time values to total seconds.