mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-19 15:26:29 +00:00
Add docs about device condition and action dynamic schema validation (#984)
This commit is contained in:
parent
9068b64e55
commit
f3b2d8ad7c
@ -10,6 +10,13 @@ Device actions are defined as dictionaries. These dictionaries are created by yo
|
|||||||
Device actions can be provided by the integration that provides the device (e.g. ZHA, deCONZ) or the entity integrations that the device has entities with (e.g. light, switch).
|
Device actions can be provided by the integration that provides the device (e.g. ZHA, deCONZ) or the entity integrations that the device has entities with (e.g. light, switch).
|
||||||
An example of the former could be to reboot the device, while an example of the latter could be to turn a light on.
|
An example of the former could be to reboot the device, while an example of the latter could be to turn a light on.
|
||||||
|
|
||||||
|
If the action requires dynamic validation that the static `ACTION_SCHEMA` can't provide, it's possible to implement an `async_validate_action_config` function.
|
||||||
|
|
||||||
|
```py
|
||||||
|
async def async_validate_action_config(hass: HomeAssistant, config: ConfigType) -> ConfigType:
|
||||||
|
"""Validate config."""
|
||||||
|
```
|
||||||
|
|
||||||
Home Assistant includes a template to get started with device actions. To get started, run inside a development environment `python3 -m script.scaffold device_action`.
|
Home Assistant includes a template to get started with device actions. To get started, run inside a development environment `python3 -m script.scaffold device_action`.
|
||||||
|
|
||||||
The template will create a new file `device_action.py` in your integration folder and a matching test file. The file contains the following functions and constants:
|
The template will create a new file `device_action.py` in your integration folder and a matching test file. The file contains the following functions and constants:
|
||||||
|
@ -10,6 +10,13 @@ Device conditions are defined as dictionaries. These dictionaries are created by
|
|||||||
Device conditions can be provided by the integration that provides the device (e.g. ZHA, deCONZ) or the entity integrations that the device has entities with (e.g. light, humidity sensor).
|
Device conditions can be provided by the integration that provides the device (e.g. ZHA, deCONZ) or the entity integrations that the device has entities with (e.g. light, humidity sensor).
|
||||||
An example of the latter could be to check if a light is on or the floor is wet.
|
An example of the latter could be to check if a light is on or the floor is wet.
|
||||||
|
|
||||||
|
If the condition requires dynamic validation that the static `CONDITION_SCHEMA` can't provide, it's possible to implement an `async_validate_condition_config` function.
|
||||||
|
|
||||||
|
```py
|
||||||
|
async def async_validate_condition_config(hass: HomeAssistant, config: ConfigType) -> ConfigType:
|
||||||
|
"""Validate config."""
|
||||||
|
```
|
||||||
|
|
||||||
Home Assistant includes a template to get started with device conditions. To get started, run inside a development environment `python3 -m script.scaffold device_condition`.
|
Home Assistant includes a template to get started with device conditions. To get started, run inside a development environment `python3 -m script.scaffold device_condition`.
|
||||||
|
|
||||||
The template will create a new file `device_condition.py` in your integration folder and a matching test file. The file contains the following functions and constants:
|
The template will create a new file `device_condition.py` in your integration folder and a matching test file. The file contains the following functions and constants:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user