From a25fc6a6d05ecf68335fe9c4cf405f5bc22e5f4b Mon Sep 17 00:00:00 2001 From: Alex Wijnholds <1023654+Alexwijn@users.noreply.github.com> Date: Tue, 27 Jun 2023 21:19:06 +0200 Subject: [PATCH] Explain `async_remove` in the Config Flow (#1792) Co-authored-by: Martin Hjelmare --- docs/data_entry_flow_index.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/data_entry_flow_index.md b/docs/data_entry_flow_index.md index ae82a845..7e68fea0 100644 --- a/docs/data_entry_flow_index.md +++ b/docs/data_entry_flow_index.md @@ -447,6 +447,23 @@ class TestFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_create_entry(title="Some title", data={}) ``` +Note: If the user closes the flow, the `async_remove` callback will be called. Make sure to implement this method in your FlowHandler to clean up any resources or tasks associated with the flow. + +```python +class TestFlow(config_entries.ConfigFlow, domain=DOMAIN): + ... + + @callback + def async_remove(self): + """Clean up resources or tasks associated with the flow.""" + if self.task_one: + self.task_one.cancel() + + if self.task_two: + self.task_two.cancel() + ... +``` + ### Show Menu This will show a navigation menu to the user to easily pick the next step. The menu labels can be hardcoded by specifying a dictionary of {`step_id`: `label`} or translated via `strings.json` when specifying a list.