Home Assistant Unofficial Reference 2024.12.1
repairs.py
Go to the documentation of this file.
1 """Repairs for Home Assistant."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
6 from homeassistant.core import HomeAssistant
7 from homeassistant.data_entry_flow import FlowResult
8 from homeassistant.helpers import issue_registry as ir
9 
10 from .const import DOMAIN
11 
12 
13 class IntegrationNotFoundFlow(RepairsFlow):
14  """Handler for an issue fixing flow."""
15 
16  def __init__(self, data: dict[str, str]) -> None:
17  """Initialize."""
18  self.domaindomain = data["domain"]
19  self.description_placeholders: dict[str, str] = data
20 
21  async def async_step_init(
22  self, user_input: dict[str, str] | None = None
23  ) -> FlowResult:
24  """Handle the first step of a fix flow."""
25  return self.async_show_menu(
26  step_id="init",
27  menu_options=["confirm", "ignore"],
28  description_placeholders=self.description_placeholders,
29  )
30 
31  async def async_step_confirm(
32  self, user_input: dict[str, str] | None = None
33  ) -> FlowResult:
34  """Handle the confirm step of a fix flow."""
35  entries = self.hass.config_entries.async_entries(self.domaindomain)
36  for entry in entries:
37  await self.hass.config_entries.async_remove(entry.entry_id)
38  return self.async_create_entry(data={})
39 
40  async def async_step_ignore(
41  self, user_input: dict[str, str] | None = None
42  ) -> FlowResult:
43  """Handle the ignore step of a fix flow."""
44  ir.async_get(self.hass).async_ignore(
45  DOMAIN, f"integration_not_found.{self.domain}", True
46  )
47  return self.async_abort(
48  reason="issue_ignored",
49  description_placeholders=self.description_placeholders,
50  )
51 
52 
54  hass: HomeAssistant, issue_id: str, data: dict[str, str] | None
55 ) -> RepairsFlow:
56  """Create flow."""
57 
58  if issue_id.split(".")[0] == "integration_not_found":
59  assert data
60  return IntegrationNotFoundFlow(data)
61  return ConfirmRepairFlow()
FlowResult async_step_confirm(self, dict[str, str]|None user_input=None)
Definition: repairs.py:33
FlowResult async_step_ignore(self, dict[str, str]|None user_input=None)
Definition: repairs.py:42
FlowResult async_step_init(self, dict[str, str]|None user_input=None)
Definition: repairs.py:23
RepairsFlow async_create_fix_flow(HomeAssistant hass, str issue_id, dict[str, str]|None data)
Definition: repairs.py:55