-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Document next_flow in async_create_entry in RepairsFlow #2985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,76 @@ async def async_create_fix_flow( | |
| return Issue1RepairFlow() | ||
| ``` | ||
|
|
||
| ### Issues that can be repaired via entry/options/subentry reconfiguration | ||
|
|
||
| Repair flows can forward issue fixes to config, options, or subentry flows: | ||
|
|
||
| ```python | ||
| from homeassistant import data_entry_flow | ||
| from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow | ||
| from homeassistant.config_entries import ( | ||
| FlowType, | ||
| SOURCE_RECONFIGURE, | ||
| SubentryFlowResult, | ||
| ) | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
|
|
||
|
|
||
| class Issue1RepairFlow(RepairsFlow): | ||
| """Handler for an issue fixing flow.""" | ||
|
|
||
| async def async_step_init( | ||
| self, user_input: dict[str, str] | None = None | ||
| ) -> data_entry_flow.FlowResult: | ||
| return await (self.async_step_confirm()) | ||
|
|
||
| async def async_step_confirm( | ||
| self, user_input: dict[str, str] | None = None | ||
| ) -> data_entry_flow.FlowResult: | ||
| """Handle the confirm step of a fix flow.""" | ||
| if user_input is not None: | ||
| next_flow: SubentryFlowResult = ( | ||
| await self.hass.config_entries.subentries.async_init( | ||
| (self.data["entry_id"], "subentry_type"), | ||
| context=SubentryFlowContext( | ||
| subentry_id=self.data["subentry_id"], | ||
| source=SOURCE_RECONFIGURE, | ||
| ), | ||
| ) | ||
| ) | ||
| return self.async_create_entry( | ||
| title="", data={}, | ||
| next_flow=( | ||
| FlowType.CONFIG_SUBENTRIES_FLOW, | ||
| next_flow["flow_id"] | ||
| ) | ||
| ) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="confirm", | ||
| data_schema=vol.Schema({}) | ||
| ) | ||
|
Comment on lines
+101
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's find the file
find . -name "repairs.md" -path "*/docs/*" | head -20Repository: home-assistant/developers.home-assistant Length of output: 115 🏁 Script executed: # Check the file size to understand what we're working with
wc -l docs/core/platform/repairs.md 2>/dev/null || echo "File not found at expected path"Repository: home-assistant/developers.home-assistant Length of output: 117 🏁 Script executed: # Extract lines 101-150 from the file to verify the snippet
sed -n '101,150p' docs/core/platform/repairs.mdRepository: home-assistant/developers.home-assistant Length of output: 1919 Add the missing This code block uses Suggested fix ```python
+import voluptuous as vol
+
from homeassistant import data_entry_flow
from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
from homeassistant.config_entries import (
FlowType,🤖 Prompt for AI Agents |
||
| ``` | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| `context = {"source": SOURCE_RECONFIGURE}` is the only context source supported for `next_flow` issue repair flows for `FlowType.CONFIG_FLOW` and `FlowType.SUBENTRIES_FLOW`. Issue repairs should not be directing to new config/options/subentry flows (which cannot be broken if they do not exist). | ||
|
|
||
| #### Example options flow | ||
|
|
||
| ```python | ||
| next_flow: ConfigFlowResult = ( | ||
| await self.hass.config_entries.options.async_init( | ||
| config_entry.entry_id | ||
| ) | ||
| ) | ||
| return self.async_create_entry( | ||
| title="", data={}, | ||
| next_flow=( | ||
| FlowType.OPTIONS_FLOW, | ||
| next_flow["flow_id"] | ||
| ) | ||
| ) | ||
| ``` | ||
iluvdata marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+154
to
+167
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n docs/core/platform/repairs.md | sed -n '140,180p'Repository: home-assistant/developers.home-assistant Length of output: 1946 🏁 Script executed: cat -n docs/core/platform/repairs.md | sed -n '100,170p'Repository: home-assistant/developers.home-assistant Length of output: 2746 🏁 Script executed: cat -n docs/core/platform/repairs.md | sed -n '1,110p'Repository: home-assistant/developers.home-assistant Length of output: 5034 🏁 Script executed: # Check if there's any documentation or code in the repository about RepairsFlow and self.config_entry
rg -A 5 "class RepairsFlow" --type python | head -50Repository: home-assistant/developers.home-assistant Length of output: 114 🏁 Script executed: # Search for RepairsFlow class definition or documentation
rg "class RepairsFlow" -A 10 | head -60Repository: home-assistant/developers.home-assistant Length of output: 66 🏁 Script executed: # Let me check the surrounding documentation to see if there's any mention of how config_entry should be accessed
cat -n docs/core/platform/repairs.md | sed -n '148,170p'Repository: home-assistant/developers.home-assistant Length of output: 884 🏁 Script executed: # Search for any documentation about how to access config_entry in repairs context
rg "options.async_init" -B 5 -A 5 docs/Repository: home-assistant/developers.home-assistant Length of output: 634 Define the config entry ID before using it in the options-flow snippet.
Suggested fix+config_entry_id = self.data["entry_id"]
next_flow: ConfigFlowResult = (
await self.hass.config_entries.options.async_init(
- config_entry.entry_id
+ config_entry_id
)
)🤖 Prompt for AI Agents |
||
|
|
||
| ## Issue life cycle | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.