1 """Provides device automations for Nest."""
3 from __future__
import annotations
5 import voluptuous
as vol
8 DEVICE_TRIGGER_BASE_SCHEMA,
9 InvalidDeviceAutomationConfig,
17 from .const
import DOMAIN
18 from .device_info
import async_nest_devices_by_device_id
19 from .events
import DEVICE_TRAIT_TRIGGER_MAP, NEST_EVENT
23 TRIGGER_TYPES = set(DEVICE_TRAIT_TRIGGER_MAP.values())
25 TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
27 vol.Required(CONF_TYPE): vol.In(TRIGGER_TYPES),
33 hass: HomeAssistant, device_id: str
34 ) -> list[dict[str, str]]:
35 """List device triggers for a Nest device."""
37 if not (device := devices.get(device_id)):
41 for trait
in device.traits
42 if (trigger_type := DEVICE_TRAIT_TRIGGER_MAP.get(trait))
46 CONF_PLATFORM: DEVICE,
47 CONF_DEVICE_ID: device_id,
49 CONF_TYPE: trigger_type,
51 for trigger_type
in trigger_types
58 action: TriggerActionType,
59 trigger_info: TriggerInfo,
61 """Attach a trigger."""
62 event_config = event_trigger.TRIGGER_SCHEMA(
64 event_trigger.CONF_PLATFORM:
"event",
65 event_trigger.CONF_EVENT_TYPE: NEST_EVENT,
66 event_trigger.CONF_EVENT_DATA: {
67 CONF_DEVICE_ID: config[CONF_DEVICE_ID],
68 CONF_TYPE: config[CONF_TYPE],
72 return await event_trigger.async_attach_trigger(
73 hass, event_config, action, trigger_info, platform_type=
"device"
Mapping[str, Device] async_nest_devices_by_device_id(HomeAssistant hass)
list[dict[str, str]] async_get_triggers(HomeAssistant hass, str device_id)
CALLBACK_TYPE async_attach_trigger(HomeAssistant hass, ConfigType config, TriggerActionType action, TriggerInfo trigger_info)