1 """Provides device automations for Lock."""
3 from __future__
import annotations
5 import voluptuous
as vol
24 from .
import DOMAIN, LockEntityFeature
26 ACTION_TYPES = {
"lock",
"unlock",
"open"}
28 _ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
30 vol.Required(CONF_TYPE): vol.In(ACTION_TYPES),
31 vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
37 hass: HomeAssistant, config: ConfigType
39 """Validate config."""
44 hass: HomeAssistant, device_id: str
45 ) -> list[dict[str, str]]:
46 """List device actions for Lock devices."""
47 registry = er.async_get(hass)
51 for entry
in er.async_entries_for_device(registry, device_id):
52 if entry.domain != DOMAIN:
59 CONF_DEVICE_ID: device_id,
61 CONF_ENTITY_ID: entry.id,
64 actions.append({**base_action, CONF_TYPE:
"lock"})
65 actions.append({**base_action, CONF_TYPE:
"unlock"})
67 if supported_features & (LockEntityFeature.OPEN):
68 actions.append({**base_action, CONF_TYPE:
"open"})
76 variables: TemplateVarsType,
77 context: Context |
None,
79 """Execute a device action."""
80 service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}
82 if config[CONF_TYPE] ==
"lock":
83 service = SERVICE_LOCK
84 elif config[CONF_TYPE] ==
"unlock":
85 service = SERVICE_UNLOCK
86 elif config[CONF_TYPE] ==
"open":
87 service = SERVICE_OPEN
89 await hass.services.async_call(
90 DOMAIN, service, service_data, blocking=
True, context=context
ConfigType async_validate_entity_schema(HomeAssistant hass, ConfigType config, VolSchemaType schema)
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)
int get_supported_features(HomeAssistant hass, str entity_id)