1 """Provides device actions for Mobile App."""
3 from __future__
import annotations
5 import voluptuous
as vol
15 from .const
import DOMAIN
16 from .util
import get_notify_service, supports_push, webhook_id_from_device_id
18 ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
20 vol.Required(CONF_TYPE):
"notify",
21 vol.Required(notify.ATTR_MESSAGE): cv.template,
22 vol.Optional(notify.ATTR_TITLE): cv.template,
23 vol.Optional(notify.ATTR_DATA): cv.template_complex,
29 hass: HomeAssistant, device_id: str
30 ) -> list[dict[str, str]]:
31 """List device actions for Mobile App devices."""
37 return [{CONF_DEVICE_ID: device_id, CONF_DOMAIN: DOMAIN, CONF_TYPE:
"notify"}]
43 variables: TemplateVarsType,
44 context: Context |
None,
46 """Execute a device action."""
49 if webhook_id
is None:
51 "Unable to resolve webhook ID from the device ID"
56 "Unable to find notify service for webhook ID"
59 service_data = {notify.ATTR_TARGET: webhook_id}
62 for key
in (notify.ATTR_MESSAGE, notify.ATTR_TITLE, notify.ATTR_DATA):
66 value_template = config[key]
69 service_data[key] = template.render_complex(value_template, variables)
70 except TemplateError
as err:
72 f
"Error rendering {key}: {err}"
75 await hass.services.async_call(
76 notify.DOMAIN, service_name, service_data, blocking=
True, context=context
81 hass: HomeAssistant, config: ConfigType
82 ) -> dict[str, vol.Schema]:
83 """List action capabilities."""
84 if config[CONF_TYPE] !=
"notify":
88 "extra_fields": vol.Schema(
90 vol.Required(notify.ATTR_MESSAGE): str,
91 vol.Optional(notify.ATTR_TITLE): str,
None async_call_action_from_config(HomeAssistant hass, ConfigType config, TemplateVarsType variables, Context|None context)
dict[str, vol.Schema] async_get_action_capabilities(HomeAssistant hass, ConfigType config)
list[dict[str, str]] async_get_actions(HomeAssistant hass, str device_id)
bool supports_push(HomeAssistant hass, str webhook_id)
str|None get_notify_service(HomeAssistant hass, str webhook_id)
str|None webhook_id_from_device_id(HomeAssistant hass, str device_id)