1 """Provides device triggers for Button."""
3 from __future__
import annotations
5 import voluptuous
as vol
9 async_attach_trigger
as async_attach_state_trigger,
10 async_validate_trigger_config
as async_validate_state_trigger_config,
24 from .const
import DOMAIN
26 TRIGGER_TYPES = {
"pressed"}
28 TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
30 vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
31 vol.Required(CONF_TYPE): vol.In(TRIGGER_TYPES),
37 hass: HomeAssistant, device_id: str
38 ) -> list[dict[str, str]]:
39 """List device triggers for button devices."""
40 registry = er.async_get(hass)
43 CONF_PLATFORM:
"device",
44 CONF_DEVICE_ID: device_id,
46 CONF_ENTITY_ID: entry.id,
49 for entry
in er.async_entries_for_device(registry, device_id)
50 if entry.domain == DOMAIN
57 action: TriggerActionType,
58 trigger_info: TriggerInfo,
60 """Attach a trigger."""
62 CONF_PLATFORM:
"state",
63 CONF_ENTITY_ID: config[CONF_ENTITY_ID],
66 state_config = await async_validate_state_trigger_config(hass, state_config)
67 return await async_attach_state_trigger(
68 hass, state_config, action, trigger_info, platform_type=
"device"