core/homeassistant/components/fan/device_action.py

44 lines
1.2 KiB
Python
Raw Normal View History

2019-11-07 11:26:10 +00:00
"""Provides device automations for Fan."""
2021-03-17 22:49:01 +00:00
from __future__ import annotations
2019-11-07 11:26:10 +00:00
import voluptuous as vol
2023-10-26 03:22:38 +00:00
from homeassistant.components.device_automation import (
async_validate_entity_schema,
toggle_entity,
)
from homeassistant.const import CONF_DOMAIN
from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
2019-11-07 11:26:10 +00:00
from . import DOMAIN
2023-10-26 03:22:38 +00:00
_ACTION_SCHEMA = toggle_entity.ACTION_SCHEMA.extend({vol.Required(CONF_DOMAIN): DOMAIN})
async def async_validate_action_config(
hass: HomeAssistant, config: ConfigType
) -> ConfigType:
"""Validate config."""
return async_validate_entity_schema(hass, config, _ACTION_SCHEMA)
2019-11-07 11:26:10 +00:00
async def async_get_actions(
hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
2019-11-07 11:26:10 +00:00
"""List device actions for Fan devices."""
return await toggle_entity.async_get_actions(hass, device_id, DOMAIN)
2019-11-07 11:26:10 +00:00
async def async_call_action_from_config(
hass: HomeAssistant,
config: ConfigType,
variables: TemplateVarsType,
context: Context | None,
2019-11-07 11:26:10 +00:00
) -> None:
"""Execute a device action."""
await toggle_entity.async_call_action_from_config(
hass, config, variables, context, DOMAIN
2019-11-07 11:26:10 +00:00
)