Update options update listener steps (#996)

* Update update listener doc

* Grammar
This commit is contained in:
Tom Brien 2021-07-04 02:33:57 +01:00 committed by GitHub
parent 2f06bbd68f
commit eee23aec0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,21 +44,15 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
## Signal updates ## 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. If the integration should act on updated options, you can register an update listener to the config entry that will be called when the entry is updated. A listener is registered by adding the following to the `async_setup_entry` function in your integration's `__init__.py`.
```python ```python
unsub = entry.add_update_listener(update_listener) entry.async_on_unload(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`. 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`.
```python ```python
async def update_listener(hass, entry): async def update_listener(hass, entry):
"""Handle options update.""" """Handle options update."""
``` ```
Don't forget to unsubscribe the update listener when your config entry is unloaded. You can do this by calling the unsubscribe function returned from adding the listener:
```python
unsub()
```