Home Assistant Unofficial Reference 2024.12.1
device_action.py
Go to the documentation of this file.
1 """Provides device actions for remotes."""
2 
3 from __future__ import annotations
4 
5 import voluptuous as vol
6 
8  async_validate_entity_schema,
9  toggle_entity,
10 )
11 from homeassistant.const import CONF_DOMAIN
12 from homeassistant.core import Context, HomeAssistant
13 from homeassistant.helpers.typing import ConfigType, TemplateVarsType
14 
15 from . import DOMAIN
16 
17 # mypy: disallow-any-generics
18 
19 _ACTION_SCHEMA = toggle_entity.ACTION_SCHEMA.extend({vol.Required(CONF_DOMAIN): DOMAIN})
20 
21 
23  hass: HomeAssistant, config: ConfigType
24 ) -> ConfigType:
25  """Validate config."""
26  return async_validate_entity_schema(hass, config, _ACTION_SCHEMA)
27 
28 
30  hass: HomeAssistant,
31  config: ConfigType,
32  variables: TemplateVarsType,
33  context: Context | None,
34 ) -> None:
35  """Change state based on configuration."""
36  await toggle_entity.async_call_action_from_config(
37  hass, config, variables, context, DOMAIN
38  )
39 
40 
42  hass: HomeAssistant, device_id: str
43 ) -> list[dict[str, str]]:
44  """List device actions."""
45  return await toggle_entity.async_get_actions(hass, device_id, DOMAIN)
ConfigType async_validate_entity_schema(HomeAssistant hass, ConfigType config, VolSchemaType schema)
Definition: __init__.py:344
ConfigType async_validate_action_config(HomeAssistant hass, ConfigType config)
None async_call_action_from_config(HomeAssistant hass, ConfigType config, TemplateVarsType variables, Context|None context)
list[dict[str, str]] async_get_actions(HomeAssistant hass, str device_id)