Support state trigger with from/for but no to (#39480)

This commit is contained in:
Anders Melchiorsen 2020-09-07 16:08:24 +02:00 committed by GitHub
parent 8a3279a5c9
commit 4b84b74b89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 1 deletions

View file

@ -925,6 +925,64 @@ async def test_if_fires_on_change_with_for_template_3(hass, calls):
assert len(calls) == 1
async def test_if_fires_on_change_from_with_for(hass, calls):
"""Test for firing on change with from/for."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "state",
"entity_id": "media_player.foo",
"from": "playing",
"for": "00:00:30",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("media_player.foo", "playing")
await hass.async_block_till_done()
hass.states.async_set("media_player.foo", "paused")
await hass.async_block_till_done()
hass.states.async_set("media_player.foo", "stopped")
await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=1))
await hass.async_block_till_done()
assert len(calls) == 1
async def test_if_not_fires_on_change_from_with_for(hass, calls):
"""Test for firing on change with from/for."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "state",
"entity_id": "media_player.foo",
"from": "playing",
"for": "00:00:30",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("media_player.foo", "playing")
await hass.async_block_till_done()
hass.states.async_set("media_player.foo", "paused")
await hass.async_block_till_done()
hass.states.async_set("media_player.foo", "playing")
await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=1))
await hass.async_block_till_done()
assert len(calls) == 0
async def test_invalid_for_template_1(hass, calls):
"""Test for invalid for template."""
assert await async_setup_component(