1 """Config flow to configure the Toon component."""
3 from __future__
import annotations
8 from toonapi
import Agreement, Toon, ToonError
9 import voluptuous
as vol
15 from .const
import CONF_AGREEMENT, CONF_AGREEMENT_ID, CONF_MIGRATE, DOMAIN
19 """Handle a Toon config flow."""
24 agreements: list[Agreement]
26 migrate_entry: str |
None =
None
31 return logging.getLogger(__name__)
34 """Test connection and load up agreements."""
38 token=self.
datadata[
"token"][
"access_token"],
52 self, import_data: dict[str, Any] |
None
53 ) -> ConfigFlowResult:
54 """Start a configuration flow based on imported data.
56 This step is merely here to trigger "discovery" when the `toon`
57 integration is listed in the user configuration, or when migrating from
61 if import_data
is not None and CONF_MIGRATE
in import_data:
69 self, user_input: dict[str, Any] |
None =
None
70 ) -> ConfigFlowResult:
71 """Select Toon agreement to add."""
76 f
"{agreement.street} {agreement.house_number}, {agreement.city}"
80 if user_input
is None:
83 data_schema=vol.Schema(
84 {vol.Required(CONF_AGREEMENT): vol.In(agreements_list)}
88 agreement_index = agreements_list.index(user_input[CONF_AGREEMENT])
91 async
def _create_entry(self, agreement: Agreement) -> ConfigFlowResult:
93 await self.hass.config_entries.async_remove(self.
migrate_entrymigrate_entry)
98 self.
datadata[CONF_AGREEMENT_ID] = agreement.agreement_id
100 title=f
"{agreement.street} {agreement.house_number}, {agreement.city}",
ConfigFlowResult _create_entry(self, Agreement agreement)
logging.Logger logger(self)
ConfigFlowResult async_step_agreement(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_import(self, dict[str, Any]|None import_data)
ConfigFlowResult async_oauth_create_entry(self, dict[str, Any] data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
None _async_handle_discovery_without_unique_id(self)
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_step_user(self, dict[str, Any]|None user_input=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)
config_entries.ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)