mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Make zone condition more robust by ignoring unavailable and unknown entities (#72751)
* ignore entities with state unavailable or unknown * test for unavailable entity
This commit is contained in:
parent
eda2be8489
commit
638992f9c4
@ -829,6 +829,12 @@ def zone(
|
||||
else:
|
||||
entity_id = entity.entity_id
|
||||
|
||||
if entity.state in (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
):
|
||||
return False
|
||||
|
||||
latitude = entity.attributes.get(ATTR_LATITUDE)
|
||||
longitude = entity.attributes.get(ATTR_LONGITUDE)
|
||||
|
||||
|
@ -4,7 +4,12 @@ import logging
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import automation, zone
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ENTITY_MATCH_ALL,
|
||||
SERVICE_TURN_OFF,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -189,6 +194,41 @@ async def test_if_fires_on_zone_leave(hass, calls):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_if_fires_on_zone_leave_2(hass, calls):
|
||||
"""Test for firing on zone leave for unavailable entity."""
|
||||
hass.states.async_set(
|
||||
"geo_location.entity",
|
||||
"hello",
|
||||
{"latitude": 32.880586, "longitude": -117.237564, "source": "test_source"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
automation.DOMAIN,
|
||||
{
|
||||
automation.DOMAIN: {
|
||||
"trigger": {
|
||||
"platform": "geo_location",
|
||||
"source": "test_source",
|
||||
"zone": "zone.test",
|
||||
"event": "enter",
|
||||
},
|
||||
"action": {"service": "test.automation"},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
hass.states.async_set(
|
||||
"geo_location.entity",
|
||||
STATE_UNAVAILABLE,
|
||||
{"source": "test_source"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_if_not_fires_for_leave_on_zone_enter(hass, calls):
|
||||
"""Test for not firing on zone enter."""
|
||||
hass.states.async_set(
|
||||
|
Loading…
x
Reference in New Issue
Block a user