You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/config_entries_options_flow_handler.md
+36-4Lines changed: 36 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,15 +25,47 @@ def async_get_options_flow(
25
25
The Flow handler works just like the config flow handler, except that the first step in the flow will always be `async_step_init`. The current config entry details are available through the `self.config_entry` property.
26
26
27
27
```python
28
-
OPTIONS_SCHEMA=vol.Schema(
28
+
from homeassistant.config_entries import OptionsFlow
29
+
30
+
OPTIONS_SCHEMA= vol.Schema(
31
+
{
32
+
vol.Required("show_things"): bool,
33
+
}
34
+
)
35
+
classOptionsFlowHandler(OptionsFlow):
36
+
asyncdefasync_step_init(
37
+
self, user_input: dict[str, Any] |None=None
38
+
) -> ConfigFlowResult:
39
+
"""Manage the options."""
40
+
if user_input isnotNone:
41
+
returnself.async_create_entry(data=user_input)
42
+
43
+
returnself.async_show_form(
44
+
step_id="init",
45
+
data_schema=self.add_suggested_values_to_schema(
46
+
OPTIONS_SCHEMA, self.config_entry.options
47
+
),
48
+
)
49
+
```
50
+
51
+
## Options flow with automatic reload
52
+
53
+
If the integration should be reloaded after the config options change, it can subclass from `OptionsFlowWithReload` instead of `OptionsFlow`. `OptionsFlowWithReload` will automatically reload the integration once the options change.
54
+
55
+
Since the most common reason to add an update listener is to reload the integration when the options have changed, `OptionsFlowWithReload` avoids the need for that listener.
56
+
57
+
```python
58
+
from homeassistant.config_entries import OptionsFlowWithReload
Using the above means the Listener is attached when the entry is loaded and detached at unload. The Listener shall be an async function that takes the same input as async_setup_entry. Options can then be accessed from `entry.options`.
0 commit comments