Fix state_automation_listener when new state is None (#32985)

* Fix state_automation_listener when new state is None (fix #32984)

* Listen to EVENT_STATE_CHANGED instead of using async_track_state_change

and use the event context on automation trigger.

* Share `process_state_match` with helpers/event

* Add test for state change automation on entity removal
This commit is contained in:
Eugenio Panadero 2020-03-24 00:05:21 +01:00 committed by GitHub
parent c2a9aba467
commit cd57b764ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 15 deletions

View file

@ -519,6 +519,28 @@ async def test_if_fires_on_entity_change_with_for(hass, calls):
assert 1 == len(calls)
async def test_if_fires_on_entity_removal(hass, calls):
"""Test for firing on entity removal, when new_state is None."""
hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done()
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "state", "entity_id": "test.entity"},
"action": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
assert hass.states.async_remove("test.entity")
await hass.async_block_till_done()
assert 1 == len(calls)
async def test_if_fires_on_for_condition(hass, calls):
"""Test for firing if condition is on."""
point1 = dt_util.utcnow()