This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+116 -110
View File
@@ -13,30 +13,32 @@ from tests.common import async_mock_service
@pytest.fixture
def calls(hass):
"""Track calls to a mock serivce."""
return async_mock_service(hass, 'test', 'automation')
return async_mock_service(hass, "test", "automation")
@pytest.fixture(autouse=True)
def setup_comp(hass):
"""Initialize components."""
mock_component(hass, 'group')
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_pattern',
'hours': 0,
'minutes': '*',
'seconds': '*',
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": 0,
"minutes": "*",
"seconds": "*",
},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done()
@@ -52,19 +54,21 @@ async def test_if_fires_when_hour_matches(hass, 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_pattern',
'hours': '*',
'minutes': 0,
'seconds': '*',
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": "*",
"minutes": 0,
"seconds": "*",
},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(minute=0))
@@ -74,19 +78,21 @@ async def test_if_fires_when_minute_matches(hass, 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_pattern',
'hours': '*',
'minutes': '*',
'seconds': 0,
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": "*",
"minutes": "*",
"seconds": 0,
},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(second=0))
@@ -96,22 +102,23 @@ async def test_if_fires_when_second_matches(hass, 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_pattern',
'hours': 1,
'minutes': 2,
'seconds': 3,
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"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))
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)
@@ -119,22 +126,23 @@ async def test_if_fires_when_all_matches(hass, 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_pattern',
'hours': '*',
'minutes': '*',
'seconds': "/2",
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": "*",
"minutes": "*",
"seconds": "/2",
},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=0, minute=0, second=2))
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)
@@ -142,22 +150,23 @@ async def test_if_fires_periodic_seconds(hass, 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_pattern',
'hours': '*',
'minutes': "/2",
'seconds': '*',
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": "*",
"minutes": "/2",
"seconds": "*",
},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=0, minute=2, second=0))
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)
@@ -165,22 +174,23 @@ async def test_if_fires_periodic_minutes(hass, 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_pattern',
'hours': "/2",
'minutes': '*',
'seconds': '*',
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time_pattern",
"hours": "/2",
"minutes": "*",
"seconds": "*",
},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=2, minute=0, second=0))
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)
@@ -188,32 +198,28 @@ async def test_if_fires_periodic_hours(hass, calls):
async def test_default_values(hass, calls):
"""Test for firing at 2 minutes every hour."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time_pattern',
'minutes': "2",
},
'action': {
'service': 'test.automation'
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "time_pattern", "minutes": "2"},
"action": {"service": "test.automation"},
}
}
})
},
)
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=1, minute=2, second=0))
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=0))
await hass.async_block_till_done()
assert 1 == len(calls)
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=1, minute=2, second=1))
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=1))
await hass.async_block_till_done()
assert 1 == len(calls)
async_fire_time_changed(hass, dt_util.utcnow().replace(
hour=2, minute=2, second=0))
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=2, minute=2, second=0))
await hass.async_block_till_done()
assert 2 == len(calls)