Use entity registry id in device_tracker device conditions (#95254)
This commit is contained in:
parent
a691846b5d
commit
16ec9b1e9f
2 changed files with 63 additions and 12 deletions
|
@ -27,7 +27,7 @@ CONDITION_TYPES = {"is_home", "is_not_home"}
|
|||
|
||||
CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
||||
vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
|
||||
vol.Required(CONF_TYPE): vol.In(CONDITION_TYPES),
|
||||
}
|
||||
)
|
||||
|
@ -50,7 +50,7 @@ async def async_get_conditions(
|
|||
CONF_CONDITION: "device",
|
||||
CONF_DEVICE_ID: device_id,
|
||||
CONF_DOMAIN: DOMAIN,
|
||||
CONF_ENTITY_ID: entry.entity_id,
|
||||
CONF_ENTITY_ID: entry.id,
|
||||
}
|
||||
|
||||
conditions += [{**base_condition, CONF_TYPE: cond} for cond in CONDITION_TYPES]
|
||||
|
@ -63,12 +63,14 @@ def async_condition_from_config(
|
|||
hass: HomeAssistant, config: ConfigType
|
||||
) -> condition.ConditionCheckerType:
|
||||
"""Create a function to test a device condition."""
|
||||
registry = er.async_get(hass)
|
||||
entity_id = er.async_resolve_entity_id(registry, config[ATTR_ENTITY_ID])
|
||||
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."""
|
||||
result = condition.state(hass, config[ATTR_ENTITY_ID], STATE_HOME)
|
||||
result = condition.state(hass, entity_id, STATE_HOME)
|
||||
if reverse:
|
||||
result = not result
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue