mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-07 17:36:29 +00:00
Dev docs for config entry options (#185)
* Dev docs for config entry options
This commit is contained in:
parent
c32dcbafca
commit
6ab90d72af
@ -3,7 +3,7 @@ title: Config Entries
|
||||
sidebar_label: Introduction
|
||||
---
|
||||
|
||||
Config Entries are configuration data that are persistently stored by Home Assistant. A config entry is created by a user via the UI. The UI flow is powered by a [config flow handler](config_entries_config_flow_handler.md) as defined by the component.
|
||||
Config Entries are configuration data that are persistently stored by Home Assistant. A config entry is created by a user via the UI. The UI flow is powered by a [config flow handler](config_entries_config_flow_handler.md) as defined by the component. Config entries can also have an extra [options flow handler](config_entries_options_flow_handler.md), also defined by the component.
|
||||
|
||||
## Setting up an entry
|
||||
|
||||
|
40
docs/config_entries_options_flow_handler.md
Normal file
40
docs/config_entries_options_flow_handler.md
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
title: Options Flow Handlers
|
||||
---
|
||||
|
||||
Config Entry Options uses the [Data Flow Entry framework](data_entry_flow_index.md) to allow users to update a config entries options. Components that want to support config entry options will need to define a Options Flow Handler.
|
||||
|
||||
## Options support
|
||||
|
||||
For a component to support options it needs to have an `async_get_options_flow` method in its config flow handler. Calling it will return an instance of the components options flow handler.
|
||||
|
||||
```python
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(config, options):
|
||||
return OptionsFlowHandler(config, options)
|
||||
```
|
||||
|
||||
## Flow handler
|
||||
|
||||
The Flow handler works just like the config flow handler, except that the first step in the flow will always be `async_step_init`.
|
||||
|
||||
```python
|
||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||
def __init__(self, config, options):
|
||||
```
|
||||
|
||||
## Signal updates
|
||||
|
||||
If the component should act on updated options, you can register an update listener to the config entry that will be called when the entry is updated.
|
||||
|
||||
```python
|
||||
entry.add_update_listener(update_listener)
|
||||
```
|
||||
|
||||
The Listener shall be an async function that takes the same input as async_setup_entry. Options can then be accessed from `entry.options`.
|
||||
|
||||
```python
|
||||
async def update_listener(hass, entry):
|
||||
```
|
||||
|
@ -36,7 +36,8 @@
|
||||
],
|
||||
"Config Entries": [
|
||||
"config_entries_index",
|
||||
"config_entries_config_flow_handler"
|
||||
"config_entries_config_flow_handler",
|
||||
"config_entries_options_flow_handler"
|
||||
],
|
||||
"Data Entry Flow": [
|
||||
"data_entry_flow_index"
|
||||
|
Loading…
x
Reference in New Issue
Block a user