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 authored and GitHub committed 2020-03-23 16:05:21 -07:00
1 parent c2a9aba467
commit cd57b764ce
3 files changed
+60 -15

No files matched your search

+22
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()