1 """Device automation helpers for entity."""
3 from __future__
import annotations
5 import voluptuous
as vol
14 from .
import DEVICE_TRIGGER_BASE_SCHEMA
15 from .const
import CONF_CHANGED_STATES
20 CONF_PLATFORM:
"device",
21 CONF_TYPE: CONF_CHANGED_STATES,
25 TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
27 vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
28 vol.Required(CONF_TYPE): vol.In([CONF_CHANGED_STATES]),
29 vol.Optional(CONF_FOR): cv.positive_time_period_dict,
37 action: TriggerActionType,
38 trigger_info: TriggerInfo,
40 """Listen for state changes based on configuration."""
43 CONF_PLATFORM:
"state",
44 state_trigger.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
45 state_trigger.CONF_TO: to_state,
47 if CONF_FOR
in config:
48 state_config[CONF_FOR] = config[CONF_FOR]
50 state_config = await state_trigger.async_validate_trigger_config(hass, state_config)
51 return await state_trigger.async_attach_trigger(
52 hass, state_config, action, trigger_info, platform_type=
"device"
59 automation_templates: list[dict[str, str]],
61 ) -> list[dict[str, str]]:
62 """List device automations."""
63 automations: list[dict[str, str]] = []
64 entity_registry = er.async_get(hass)
68 for entry
in er.async_entries_for_device(entity_registry, device_id)
69 if entry.domain == domain
76 "device_id": device_id,
77 "entity_id": entry.id,
80 for template
in automation_templates
87 hass: HomeAssistant, device_id: str, domain: str
88 ) -> list[dict[str, str]]:
89 """List device triggers."""
94 hass: HomeAssistant, config: ConfigType
95 ) -> dict[str, vol.Schema]:
96 """List trigger capabilities."""
98 "extra_fields": vol.Schema(
99 {vol.Optional(CONF_FOR): cv.positive_time_period_dict}
CALLBACK_TYPE async_attach_trigger(HomeAssistant hass, ConfigType config, TriggerActionType action, TriggerInfo trigger_info)
dict[str, vol.Schema] async_get_trigger_capabilities(HomeAssistant hass, ConfigType config)
list[dict[str, str]] async_get_triggers(HomeAssistant hass, str device_id, str domain)
list[dict[str, str]] _async_get_automations(HomeAssistant hass, str device_id, list[dict[str, str]] automation_templates, str domain)