Home Assistant Unofficial Reference 2024.12.1
repairs.py
Go to the documentation of this file.
1 """Repairs platform for the demo integration."""
2 
3 from __future__ import annotations
4 
5 import voluptuous as vol
6 
7 from homeassistant import data_entry_flow
8 from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
9 from homeassistant.core import HomeAssistant
10 
11 
12 class DemoFixFlow(RepairsFlow):
13  """Handler for an issue fixing flow."""
14 
15  async def async_step_init(
16  self, user_input: dict[str, str] | None = None
18  """Handle the first step of a fix flow."""
19 
20  return await self.async_step_confirm()
21 
22  async def async_step_confirm(
23  self, user_input: dict[str, str] | None = None
25  """Handle the confirm step of a fix flow."""
26  if user_input is not None:
27  return self.async_create_entry(data={})
28 
29  return self.async_show_form(step_id="confirm", data_schema=vol.Schema({}))
30 
31 
32 class DemoColdTeaFixFlow(RepairsFlow):
33  """Handler for cold tea."""
34 
35  async def async_step_init(
36  self, user_input: dict[str, str] | None = None
38  """Handle the first step of a fix flow."""
39  return self.async_abort(reason="not_tea_time")
40 
41 
43  hass: HomeAssistant,
44  issue_id: str,
45  data: dict[str, str | int | float | None] | None,
46 ) -> RepairsFlow:
47  """Create flow."""
48  if issue_id == "bad_psu":
49  # The bad_psu issue doesn't have its own flow
50  return ConfirmRepairFlow()
51 
52  if issue_id == "cold_tea":
53  # The cold_tea issue have it's own flow
54  return DemoColdTeaFixFlow()
55 
56  # Other issues have a custom flow
57  return DemoFixFlow()
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
Definition: repairs.py:37
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
Definition: repairs.py:17
RepairsFlow async_create_fix_flow(HomeAssistant hass, str issue_id, dict[str, str|int|float|None]|None data)
Definition: repairs.py:46
config_entries.ConfigFlowResult async_step_confirm(self, dict[str, Any]|None user_input=None)