1 """Provides device automations for RFXCOM RFXtrx."""
3 from __future__
import annotations
5 from collections.abc
import Callable
7 import voluptuous
as vol
15 from .
import DATA_RFXOBJECT, DOMAIN
16 from .helpers
import async_get_device_object
19 CONF_SUBTYPE =
"subtype"
21 ACTION_TYPE_COMMAND =
"send_command"
22 ACTION_TYPE_STATUS =
"send_status"
30 ACTION_TYPE_COMMAND:
"COMMANDS",
31 ACTION_TYPE_STATUS:
"STATUS",
34 ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
36 vol.Required(CONF_TYPE): vol.In(ACTION_TYPES),
37 vol.Required(CONF_SUBTYPE): str,
43 hass: HomeAssistant, device_id: str
44 ) -> list[dict[str, str]]:
45 """List device actions for RFXCOM RFXtrx devices."""
54 CONF_DEVICE_ID: device_id,
56 CONF_TYPE: action_type,
59 for action_type
in ACTION_TYPES
60 if hasattr(device, action_type)
61 for value
in getattr(device, ACTION_SELECTION[action_type], {}).values()
66 hass: HomeAssistant, device_id: str, action_type: str
67 ) -> tuple[dict[str, str], Callable[...,
None]]:
69 send_fun = getattr(device, action_type)
70 commands = getattr(device, ACTION_SELECTION[action_type], {})
71 return commands, send_fun
75 hass: HomeAssistant, config: ConfigType
77 """Validate config."""
79 commands, _ =
_get_commands(hass, config[CONF_DEVICE_ID], config[CONF_TYPE])
80 sub_type = config[CONF_SUBTYPE]
82 if sub_type
not in commands.values():
84 f
"Subtype {sub_type} not found in device commands {commands}"
93 variables: TemplateVarsType,
94 context: Context |
None,
96 """Execute a device action."""
99 rfx = hass.data[DOMAIN][DATA_RFXOBJECT]
100 commands, send_fun =
_get_commands(hass, config[CONF_DEVICE_ID], config[CONF_TYPE])
101 sub_type = config[CONF_SUBTYPE]
103 for key, value
in commands.items():
104 if value == sub_type:
105 await hass.async_add_executor_job(send_fun, rfx.transport, key)
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)
tuple[dict[str, str], Callable[..., None]] _get_commands(HomeAssistant hass, str device_id, str action_type)
RFXtrxDevice async_get_device_object(HomeAssistant hass, str device_id)