Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow to configure the CPU Speed integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from cpuinfo import cpuinfo
8 
9 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
10 
11 from .const import DOMAIN
12 
13 
14 class CPUSpeedFlowHandler(ConfigFlow, domain=DOMAIN):
15  """Config flow for CPU Speed."""
16 
17  VERSION = 1
18 
19  _imported_name: str | None = None
20 
21  async def async_step_user(
22  self, user_input: dict[str, Any] | None = None
23  ) -> ConfigFlowResult:
24  """Handle a flow initialized by the user."""
25  await self.async_set_unique_idasync_set_unique_id(DOMAIN)
26 
27  if user_input is None:
28  return self.async_show_formasync_show_formasync_show_form(step_id="user")
29 
30  if not await self.hass.async_add_executor_job(cpuinfo.get_cpu_info):
31  return self.async_abortasync_abortasync_abort(reason="not_compatible")
32 
33  return self.async_create_entryasync_create_entryasync_create_entry(
34  title=self._imported_name or "CPU Speed",
35  data={},
36  )
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:23
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)