Don't trigger on attribute when the attribute doesn't change (#39910)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>pull/39974/head
parent
f59e727f16
commit
c2a9a39ee0
|
@ -80,6 +80,13 @@ async def async_attach_trigger(
|
|||
else:
|
||||
new_value = to_s.attributes.get(attribute)
|
||||
|
||||
# When we listen for state changes with `match_all`, we
|
||||
# will trigger even if just an attribute changes. When
|
||||
# we listen to just an attribute, we should ignore all
|
||||
# other attribute changes.
|
||||
if attribute is not None and old_value == new_value:
|
||||
return
|
||||
|
||||
if (
|
||||
not match_from_state(old_value)
|
||||
or not match_to_state(new_value)
|
||||
|
|
|
@ -1112,6 +1112,42 @@ async def test_attribute_if_fires_on_entity_change_with_both_filters(hass, calls
|
|||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attribute_if_fires_on_entity_where_attr_stays_constant(hass, calls):
|
||||
"""Test for firing if attribute stays the same."""
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello", "other": "old_value"})
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
automation.DOMAIN,
|
||||
{
|
||||
automation.DOMAIN: {
|
||||
"trigger": {
|
||||
"platform": "state",
|
||||
"entity_id": "test.entity",
|
||||
"attribute": "name",
|
||||
},
|
||||
"action": {"service": "test.automation"},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Leave all attributes the same
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello", "other": "old_value"})
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
|
||||
# Change the untracked attribute
|
||||
hass.states.async_set("test.entity", "bla", {"name": "hello", "other": "new_value"})
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
|
||||
# Change the tracked attribute
|
||||
hass.states.async_set("test.entity", "bla", {"name": "world", "other": "old_value"})
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attribute_if_not_fires_on_entities_change_with_for_after_stop(
|
||||
hass, calls
|
||||
):
|
||||
|
|
Loading…
Reference in New Issue