1 """Provides device automations for Device tracker."""
3 from __future__
import annotations
5 import voluptuous
as vol
19 config_validation
as cv,
20 entity_registry
as er,
25 from .const
import DOMAIN
27 CONDITION_TYPES = {
"is_home",
"is_not_home"}
29 CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
31 vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
32 vol.Required(CONF_TYPE): vol.In(CONDITION_TYPES),
38 hass: HomeAssistant, device_id: str
39 ) -> list[dict[str, str]]:
40 """List device conditions for Device tracker devices."""
41 registry = er.async_get(hass)
45 for entry
in er.async_entries_for_device(registry, device_id):
46 if entry.domain != DOMAIN:
51 CONF_CONDITION:
"device",
52 CONF_DEVICE_ID: device_id,
54 CONF_ENTITY_ID: entry.id,
57 conditions += [{**base_condition, CONF_TYPE: cond}
for cond
in CONDITION_TYPES]
64 hass: HomeAssistant, config: ConfigType
65 ) -> condition.ConditionCheckerType:
66 """Create a function to test a device condition."""
67 registry = er.async_get(hass)
68 entity_id = er.async_resolve_entity_id(registry, config[ATTR_ENTITY_ID])
69 reverse = config[CONF_TYPE] ==
"is_not_home"
72 def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
73 """Test if an entity is a certain state."""
74 result = condition.state(hass, entity_id, STATE_HOME)
list[dict[str, str]] async_get_conditions(HomeAssistant hass, str device_id)
condition.ConditionCheckerType async_condition_from_config(HomeAssistant hass, ConfigType config)