1 """Config flow for Minecraft Server integration."""
3 from __future__
import annotations
8 import voluptuous
as vol
13 from .api
import MinecraftServer, MinecraftServerAddressError, MinecraftServerType
14 from .const
import DEFAULT_NAME, DOMAIN
16 DEFAULT_ADDRESS =
"localhost:25565"
18 _LOGGER = logging.getLogger(__name__)
22 """Handle a config flow for Minecraft Server."""
27 self, user_input: dict[str, Any] |
None =
None
28 ) -> ConfigFlowResult:
29 """Handle the initial step."""
30 errors: dict[str, str] = {}
33 address = user_input[CONF_ADDRESS]
40 CONF_NAME: user_input[CONF_NAME],
41 CONF_ADDRESS: address,
45 for server_type
in MinecraftServerType:
49 await api.async_initialize()
50 except MinecraftServerAddressError
as error:
52 "Initialization of %s server failed: %s",
57 if await api.async_is_online():
58 config_data[CONF_TYPE] = server_type
62 errors[
"base"] =
"cannot_connect"
70 user_input: dict[str, Any] |
None =
None,
71 errors: dict[str, str] |
None =
None,
72 ) -> ConfigFlowResult:
73 """Show the setup form to the user."""
74 if user_input
is None:
79 data_schema=vol.Schema(
82 CONF_NAME, default=user_input.get(CONF_NAME, DEFAULT_NAME)
86 default=user_input.get(CONF_ADDRESS, DEFAULT_ADDRESS),
87 ): vol.All(str, vol.Lower),
ConfigFlowResult _show_config_form(self, dict[str, Any]|None user_input=None, dict[str, str]|None errors=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)