mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix bug in state trigger when using for: without to: (#40556)
This commit is contained in:
parent
4287694b42
commit
371b589cb2
@ -145,7 +145,7 @@ async def async_attach_trigger(
|
|||||||
else:
|
else:
|
||||||
cur_value = new_st.attributes.get(attribute)
|
cur_value = new_st.attributes.get(attribute)
|
||||||
|
|
||||||
if CONF_TO not in config:
|
if CONF_FROM in config and CONF_TO not in config:
|
||||||
return cur_value != old_value
|
return cur_value != old_value
|
||||||
|
|
||||||
return cur_value == new_value
|
return cur_value == new_value
|
||||||
|
@ -538,6 +538,39 @@ async def test_if_fires_on_entity_change_with_for_without_to(hass, calls):
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_if_does_not_fires_on_entity_change_with_for_without_to_2(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()
|
||||||
|
|
||||||
|
utcnow = dt_util.utcnow()
|
||||||
|
with patch("homeassistant.core.dt_util.utcnow") as mock_utcnow:
|
||||||
|
mock_utcnow.return_value = utcnow
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
hass.states.async_set("test.entity", str(i))
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
mock_utcnow.return_value += timedelta(seconds=1)
|
||||||
|
async_fire_time_changed(hass, mock_utcnow.return_value)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
|
||||||
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