mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Support 'for' without setting the 'to'-state in automation state triggers (#39730)
This commit is contained in:
parent
8c96eb7c56
commit
7c86fa0203
@ -25,8 +25,7 @@ CONF_ENTITY_ID = "entity_id"
|
|||||||
CONF_FROM = "from"
|
CONF_FROM = "from"
|
||||||
CONF_TO = "to"
|
CONF_TO = "to"
|
||||||
|
|
||||||
TRIGGER_SCHEMA = vol.All(
|
TRIGGER_SCHEMA = vol.Schema(
|
||||||
vol.Schema(
|
|
||||||
{
|
{
|
||||||
vol.Required(CONF_PLATFORM): "state",
|
vol.Required(CONF_PLATFORM): "state",
|
||||||
vol.Required(CONF_ENTITY_ID): cv.entity_ids,
|
vol.Required(CONF_ENTITY_ID): cv.entity_ids,
|
||||||
@ -36,11 +35,6 @@ TRIGGER_SCHEMA = vol.All(
|
|||||||
vol.Optional(CONF_FOR): cv.positive_time_period_template,
|
vol.Optional(CONF_FOR): cv.positive_time_period_template,
|
||||||
vol.Optional(CONF_ATTRIBUTE): cv.match_all,
|
vol.Optional(CONF_ATTRIBUTE): cv.match_all,
|
||||||
}
|
}
|
||||||
),
|
|
||||||
vol.Any(
|
|
||||||
cv.key_dependency(CONF_FOR, CONF_TO),
|
|
||||||
cv.key_dependency(CONF_FOR, CONF_FROM),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,25 +334,6 @@ async def test_if_fails_setup_bad_for(hass, calls):
|
|||||||
assert mock_logger.error.called
|
assert mock_logger.error.called
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fails_setup_for_without_to(hass, calls):
|
|
||||||
"""Test for setup failures for missing to."""
|
|
||||||
with assert_setup_component(0, automation.DOMAIN):
|
|
||||||
assert await async_setup_component(
|
|
||||||
hass,
|
|
||||||
automation.DOMAIN,
|
|
||||||
{
|
|
||||||
automation.DOMAIN: {
|
|
||||||
"trigger": {
|
|
||||||
"platform": "state",
|
|
||||||
"entity_id": "test.entity",
|
|
||||||
"for": {"seconds": 5},
|
|
||||||
},
|
|
||||||
"action": {"service": "homeassistant.turn_on"},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_if_not_fires_on_entity_change_with_for(hass, calls):
|
async def test_if_not_fires_on_entity_change_with_for(hass, calls):
|
||||||
"""Test for not firing on entity change with for."""
|
"""Test for not firing on entity change with for."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
@ -520,6 +501,43 @@ async def test_if_fires_on_entity_change_with_for(hass, calls):
|
|||||||
assert 1 == len(calls)
|
assert 1 == len(calls)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_if_fires_on_entity_change_with_for_without_to(hass, calls):
|
||||||
|
"""Test for firing on entity change with for."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
automation.DOMAIN,
|
||||||
|
{
|
||||||
|
automation.DOMAIN: {
|
||||||
|
"trigger": {
|
||||||
|
"platform": "state",
|
||||||
|
"entity_id": "test.entity",
|
||||||
|
"for": {"seconds": 5},
|
||||||
|
},
|
||||||
|
"action": {"service": "test.automation"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
hass.states.async_set("test.entity", "hello")
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=2))
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
hass.states.async_set("test.entity", "world")
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4))
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_entity_creation_and_removal(hass, calls):
|
async def test_if_fires_on_entity_creation_and_removal(hass, calls):
|
||||||
"""Test for firing on entity creation and removal, with to/from constraints."""
|
"""Test for firing on entity creation and removal, with to/from constraints."""
|
||||||
# set automations for multiple combinations to/from
|
# set automations for multiple combinations to/from
|
||||||
|
Loading…
x
Reference in New Issue
Block a user