Correctly detect is not home (#53279)
This commit is contained in:
parent
217c625c9b
commit
ba00c786b0
2 changed files with 8 additions and 8 deletions
|
@ -11,7 +11,6 @@ from homeassistant.const import (
|
|||
CONF_ENTITY_ID,
|
||||
CONF_TYPE,
|
||||
STATE_HOME,
|
||||
STATE_NOT_HOME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import condition, config_validation as cv, entity_registry
|
||||
|
@ -62,14 +61,15 @@ def async_condition_from_config(
|
|||
"""Create a function to test a device condition."""
|
||||
if config_validation:
|
||||
config = CONDITION_SCHEMA(config)
|
||||
if config[CONF_TYPE] == "is_home":
|
||||
state = STATE_HOME
|
||||
else:
|
||||
state = STATE_NOT_HOME
|
||||
|
||||
reverse = config[CONF_TYPE] == "is_not_home"
|
||||
|
||||
@callback
|
||||
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
|
||||
"""Test if an entity is a certain state."""
|
||||
return condition.state(hass, config[ATTR_ENTITY_ID], state)
|
||||
result = condition.state(hass, config[ATTR_ENTITY_ID], STATE_HOME)
|
||||
if reverse:
|
||||
result = not result
|
||||
return result
|
||||
|
||||
return test_is_state
|
||||
|
|
|
@ -3,7 +3,7 @@ import pytest
|
|||
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.device_tracker import DOMAIN
|
||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
||||
from homeassistant.const import STATE_HOME
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -119,7 +119,7 @@ async def test_if_state(hass, calls):
|
|||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "is_home - event - test_event1"
|
||||
|
||||
hass.states.async_set("device_tracker.entity", STATE_NOT_HOME)
|
||||
hass.states.async_set("device_tracker.entity", "school")
|
||||
hass.bus.async_fire("test_event1")
|
||||
hass.bus.async_fire("test_event2")
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Reference in a new issue