2019-09-24 14:57:05 -07:00
|
|
|
"""Provides device triggers for switches."""
|
2021-03-18 14:31:38 +01:00
|
|
|
from __future__ import annotations
|
2019-12-08 18:50:17 +01:00
|
|
|
|
2019-09-24 14:57:05 -07:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from homeassistant.components.device_automation import toggle_entity
|
|
|
|
from homeassistant.const import CONF_DOMAIN
|
2019-12-08 18:50:17 +01:00
|
|
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
2022-08-15 17:40:16 +02:00
|
|
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
2019-09-24 14:57:05 -07:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
|
2019-12-08 18:50:17 +01:00
|
|
|
from . import DOMAIN
|
2019-09-24 14:57:05 -07:00
|
|
|
|
2022-01-03 10:41:30 +01:00
|
|
|
TRIGGER_SCHEMA = vol.All(
|
|
|
|
toggle_entity.TRIGGER_SCHEMA,
|
|
|
|
vol.Schema({vol.Required(CONF_DOMAIN): DOMAIN}, extra=vol.ALLOW_EXTRA),
|
2019-09-24 14:57:05 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_attach_trigger(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
2022-08-15 17:40:16 +02:00
|
|
|
action: TriggerActionType,
|
|
|
|
trigger_info: TriggerInfo,
|
2019-09-24 14:57:05 -07:00
|
|
|
) -> CALLBACK_TYPE:
|
|
|
|
"""Listen for state changes based on configuration."""
|
2022-08-15 17:40:16 +02:00
|
|
|
return await toggle_entity.async_attach_trigger(hass, config, action, trigger_info)
|
2019-09-24 14:57:05 -07:00
|
|
|
|
|
|
|
|
2021-08-22 21:32:50 +03:00
|
|
|
async def async_get_triggers(
|
|
|
|
hass: HomeAssistant, device_id: str
|
2022-05-23 16:01:40 +02:00
|
|
|
) -> list[dict[str, str]]:
|
2019-09-24 14:57:05 -07:00
|
|
|
"""List device triggers."""
|
|
|
|
return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)
|
2019-10-02 22:14:52 +02:00
|
|
|
|
|
|
|
|
2021-08-22 21:32:50 +03:00
|
|
|
async def async_get_trigger_capabilities(
|
|
|
|
hass: HomeAssistant, config: ConfigType
|
|
|
|
) -> dict[str, vol.Schema]:
|
2019-10-02 22:14:52 +02:00
|
|
|
"""List trigger capabilities."""
|
2019-10-03 22:29:57 +02:00
|
|
|
return await toggle_entity.async_get_trigger_capabilities(hass, config)
|