Home Assistant Unofficial Reference 2024.12.1
device_trigger.py
Go to the documentation of this file.
1 """Provides device automations for Fan."""
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, device_id: str
23 ) -> list[dict[str, str]]:
24  """List device triggers for Fan devices."""
25  return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)
26 
27 
29  hass: HomeAssistant, config: ConfigType
30 ) -> dict[str, vol.Schema]:
31  """List trigger capabilities."""
32  return await toggle_entity.async_get_trigger_capabilities(hass, config)
33 
34 
36  hass: HomeAssistant,
37  config: ConfigType,
38  action: TriggerActionType,
39  trigger_info: TriggerInfo,
40 ) -> CALLBACK_TYPE:
41  """Listen for state changes based on configuration."""
42  return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
CALLBACK_TYPE async_attach_trigger(HomeAssistant hass, ConfigType config, TriggerActionType action, TriggerInfo trigger_info)
list[dict[str, str]] async_get_triggers(HomeAssistant hass, str device_id)
dict[str, vol.Schema] async_get_trigger_capabilities(HomeAssistant hass, ConfigType config)