Home Assistant Unofficial Reference 2024.12.1
repair_flows.py
Go to the documentation of this file.
1 """Repairs implementation for the cloud integration."""
2 
3 from __future__ import annotations
4 
5 from typing import cast
6 
7 import voluptuous as vol
8 
9 from homeassistant.components.assist_satellite import DOMAIN as ASSIST_SATELLITE_DOMAIN
10 from homeassistant.components.repairs import RepairsFlow
11 from homeassistant.data_entry_flow import FlowResult
12 from homeassistant.helpers import entity_registry as er
13 
14 REQUIRED_KEYS = ("entity_id", "entity_uuid", "integration_name")
15 
16 
18  """Handler for an issue fixing flow."""
19 
20  def __init__(self, data: dict[str, str | int | float | None] | None) -> None:
21  """Initialize."""
22  if not data or any(key not in data for key in REQUIRED_KEYS):
23  raise ValueError("Missing data")
24  self._data_data = data
25 
26  async def async_step_init(self, _: None = None) -> FlowResult:
27  """Handle the first step of a fix flow."""
28  return await self.async_step_confirm_disable_entityasync_step_confirm_disable_entity()
29 
31  self,
32  user_input: dict[str, str] | None = None,
33  ) -> FlowResult:
34  """Handle the confirm step of a fix flow."""
35  if user_input is not None:
36  entity_registry = er.async_get(self.hass)
37  entity_entry = entity_registry.async_get(
38  cast(str, self._data_data["entity_uuid"])
39  )
40  if entity_entry:
41  entity_registry.async_update_entity(
42  entity_entry.entity_id, disabled_by=er.RegistryEntryDisabler.USER
43  )
44  return self.async_create_entry(data={})
45 
46  description_placeholders: dict[str, str] = {
47  "assist_satellite_domain": ASSIST_SATELLITE_DOMAIN,
48  "entity_id": cast(str, self._data_data["entity_id"]),
49  "integration_name": cast(str, self._data_data["integration_name"]),
50  }
51  return self.async_show_form(
52  step_id="confirm_disable_entity",
53  data_schema=vol.Schema({}),
54  description_placeholders=description_placeholders,
55  )
FlowResult async_step_confirm_disable_entity(self, dict[str, str]|None user_input=None)
Definition: repair_flows.py:33