1 """Provide the device automations for Fan."""
3 from __future__
import annotations
5 import voluptuous
as vol
20 config_validation
as cv,
21 entity_registry
as er,
28 CONDITION_TYPES = {
"is_on",
"is_off"}
30 CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
32 vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
33 vol.Required(CONF_TYPE): vol.In(CONDITION_TYPES),
39 hass: HomeAssistant, device_id: str
40 ) -> list[dict[str, str]]:
41 """List device conditions for Fan devices."""
42 registry = er.async_get(hass)
46 for entry
in er.async_entries_for_device(registry, device_id):
47 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])
70 if config[CONF_TYPE] ==
"is_on":
76 def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
77 """Test if an entity is a certain state."""
78 return condition.state(hass, entity_id, state)
condition.ConditionCheckerType async_condition_from_config(HomeAssistant hass, ConfigType config)
list[dict[str, str]] async_get_conditions(HomeAssistant hass, str device_id)