Home Assistant Unofficial Reference 2024.12.1
device_trigger.py
Go to the documentation of this file.
1 """Provides device triggers for remotes."""
2 
3 from __future__ import annotations
4 
5 import voluptuous as vol
6 
7 from homeassistant.components.device_automation import toggle_entity
8 from homeassistant.const import CONF_DOMAIN
9 from homeassistant.core import CALLBACK_TYPE, HomeAssistant
10 from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
11 from homeassistant.helpers.typing import ConfigType
12 
13 from . import DOMAIN
14 
15 TRIGGER_SCHEMA = vol.All(
16  toggle_entity.TRIGGER_SCHEMA,
17  vol.Schema({vol.Required(CONF_DOMAIN): DOMAIN}, extra=vol.ALLOW_EXTRA),
18 )
19 
20 
22  hass: HomeAssistant,
23  config: ConfigType,
24  action: TriggerActionType,
25  trigger_info: TriggerInfo,
26 ) -> CALLBACK_TYPE:
27  """Listen for state changes based on configuration."""
28  return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
29 
30 
32  hass: HomeAssistant, device_id: str
33 ) -> list[dict[str, str]]:
34  """List device triggers."""
35  return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)
36 
37 
39  hass: HomeAssistant, config: ConfigType
40 ) -> dict[str, vol.Schema]:
41  """List trigger capabilities."""
42  return await toggle_entity.async_get_trigger_capabilities(hass, config)
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)