Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for Google Translate text-to-speech integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 import voluptuous as vol
8 
9 from homeassistant.components.tts import CONF_LANG
10 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
11 
12 from .const import (
13  CONF_TLD,
14  DEFAULT_LANG,
15  DEFAULT_TLD,
16  DOMAIN,
17  SUPPORT_LANGUAGES,
18  SUPPORT_TLD,
19 )
20 
21 STEP_USER_DATA_SCHEMA = vol.Schema(
22  {
23  vol.Optional(CONF_LANG, default=DEFAULT_LANG): vol.In(SUPPORT_LANGUAGES),
24  vol.Optional(CONF_TLD, default=DEFAULT_TLD): vol.In(SUPPORT_TLD),
25  }
26 )
27 
28 
29 class GoogleTranslateConfigFlow(ConfigFlow, domain=DOMAIN):
30  """Handle a config flow for Google Translate text-to-speech."""
31 
32  VERSION = 1
33 
34  async def async_step_user(
35  self, user_input: dict[str, Any] | None = None
36  ) -> ConfigFlowResult:
37  """Handle the initial step."""
38  if user_input is not None:
39  self._async_abort_entries_match_async_abort_entries_match(
40  {
41  CONF_LANG: user_input[CONF_LANG],
42  CONF_TLD: user_input[CONF_TLD],
43  }
44  )
45  return self.async_create_entryasync_create_entryasync_create_entry(
46  title="Google Translate text-to-speech", data=user_input
47  )
48 
49  return self.async_show_formasync_show_formasync_show_form(step_id="user", data_schema=STEP_USER_DATA_SCHEMA)
50 
52  self, data: dict[str, Any] | None = None
53  ) -> ConfigFlowResult:
54  """Handle a flow initialized by onboarding."""
55  return self.async_create_entryasync_create_entryasync_create_entry(
56  title="Google Translate text-to-speech",
57  data={CONF_LANG: DEFAULT_LANG, CONF_TLD: DEFAULT_TLD},
58  )
ConfigFlowResult async_step_onboarding(self, dict[str, Any]|None data=None)
Definition: config_flow.py:53
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:36
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)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)