2019-09-24 21:57:05 +00:00
|
|
|
"""Provides device triggers for switches."""
|
2021-03-18 13:31:38 +00:00
|
|
|
from __future__ import annotations
|
2019-12-08 17:50:17 +00:00
|
|
|
|
2021-08-22 18:32:50 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2019-09-24 21:57:05 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2021-09-04 00:25:51 +00:00
|
|
|
from homeassistant.components.automation import (
|
|
|
|
AutomationActionType,
|
|
|
|
AutomationTriggerInfo,
|
|
|
|
)
|
2019-09-24 21:57:05 +00:00
|
|
|
from homeassistant.components.device_automation import toggle_entity
|
|
|
|
from homeassistant.const import CONF_DOMAIN
|
2019-12-08 17:50:17 +00:00
|
|
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
2019-09-24 21:57:05 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
|
2019-12-08 17:50:17 +00:00
|
|
|
from . import DOMAIN
|
2019-09-24 21:57:05 +00:00
|
|
|
|
|
|
|
TRIGGER_SCHEMA = toggle_entity.TRIGGER_SCHEMA.extend(
|
|
|
|
{vol.Required(CONF_DOMAIN): DOMAIN}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_attach_trigger(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
action: AutomationActionType,
|
2021-09-04 00:25:51 +00:00
|
|
|
automation_info: AutomationTriggerInfo,
|
2019-09-24 21:57:05 +00:00
|
|
|
) -> CALLBACK_TYPE:
|
|
|
|
"""Listen for state changes based on configuration."""
|
|
|
|
return await toggle_entity.async_attach_trigger(
|
|
|
|
hass, config, action, automation_info
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-22 18:32:50 +00:00
|
|
|
async def async_get_triggers(
|
|
|
|
hass: HomeAssistant, device_id: str
|
|
|
|
) -> list[dict[str, Any]]:
|
2019-09-24 21:57:05 +00:00
|
|
|
"""List device triggers."""
|
|
|
|
return await toggle_entity.async_get_triggers(hass, device_id, DOMAIN)
|
2019-10-02 20:14:52 +00:00
|
|
|
|
|
|
|
|
2021-08-22 18:32:50 +00:00
|
|
|
async def async_get_trigger_capabilities(
|
|
|
|
hass: HomeAssistant, config: ConfigType
|
|
|
|
) -> dict[str, vol.Schema]:
|
2019-10-02 20:14:52 +00:00
|
|
|
"""List trigger capabilities."""
|
2019-10-03 20:29:57 +00:00
|
|
|
return await toggle_entity.async_get_trigger_capabilities(hass, config)
|