mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Improve warnings when a zone trigger is referencing a none-existing zone (#61763)
This commit is contained in:
parent
d9105b071a
commit
cf09d1b604
@ -1,4 +1,6 @@
|
|||||||
"""Offer zone automation rules."""
|
"""Offer zone automation rules."""
|
||||||
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -25,6 +27,8 @@ EVENT_ENTER = "enter"
|
|||||||
EVENT_LEAVE = "leave"
|
EVENT_LEAVE = "leave"
|
||||||
DEFAULT_EVENT = EVENT_ENTER
|
DEFAULT_EVENT = EVENT_ENTER
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
_EVENT_DESCRIPTION = {EVENT_ENTER: "entering", EVENT_LEAVE: "leaving"}
|
_EVENT_DESCRIPTION = {EVENT_ENTER: "entering", EVENT_LEAVE: "leaving"}
|
||||||
|
|
||||||
_TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
_TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
||||||
@ -76,6 +80,14 @@ async def async_attach_trigger(
|
|||||||
return
|
return
|
||||||
|
|
||||||
zone_state = hass.states.get(zone_entity_id)
|
zone_state = hass.states.get(zone_entity_id)
|
||||||
|
if not zone_state:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Automation '%s' is referencing non-existing zone '%s' in a zone trigger",
|
||||||
|
automation_info["name"],
|
||||||
|
zone_entity_id,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
from_match = condition.zone(hass, zone_state, from_s) if from_s else False
|
from_match = condition.zone(hass, zone_state, from_s) if from_s else False
|
||||||
to_match = condition.zone(hass, zone_state, to_s) if to_s else False
|
to_match = condition.zone(hass, zone_state, to_s) if to_s else False
|
||||||
|
|
||||||
|
@ -307,3 +307,49 @@ async def test_zone_condition(hass, calls):
|
|||||||
hass.bus.async_fire("test_event")
|
hass.bus.async_fire("test_event")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unknown_zone(hass, calls, caplog):
|
||||||
|
"""Test for firing on zone enter."""
|
||||||
|
context = Context()
|
||||||
|
hass.states.async_set(
|
||||||
|
"test.entity", "hello", {"latitude": 32.881011, "longitude": -117.234758}
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
automation.DOMAIN,
|
||||||
|
{
|
||||||
|
automation.DOMAIN: {
|
||||||
|
"alias": "My Automation",
|
||||||
|
"trigger": {
|
||||||
|
"platform": "zone",
|
||||||
|
"entity_id": "test.entity",
|
||||||
|
"zone": "zone.no_such_zone",
|
||||||
|
"event": "enter",
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"service": "test.automation",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"Automation 'My Automation' is referencing non-existing zone 'zone.no_such_zone' in a zone trigger"
|
||||||
|
not in caplog.text
|
||||||
|
)
|
||||||
|
|
||||||
|
hass.states.async_set(
|
||||||
|
"test.entity",
|
||||||
|
"hello",
|
||||||
|
{"latitude": 32.880586, "longitude": -117.237564},
|
||||||
|
context=context,
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"Automation 'My Automation' is referencing non-existing zone 'zone.no_such_zone' in a zone trigger"
|
||||||
|
in caplog.text
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user