1 """Config flow for FiveM integration."""
3 from __future__
import annotations
8 from fivem
import FiveM, FiveMServerOfflineError
9 import voluptuous
as vol
15 from .const
import DOMAIN
17 _LOGGER = logging.getLogger(__name__)
21 STEP_USER_DATA_SCHEMA = vol.Schema(
23 vol.Required(CONF_HOST): cv.string,
24 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
30 """Validate the user input allows us to connect."""
32 fivem = FiveM(data[CONF_HOST], data[CONF_PORT])
33 info = await fivem.get_info_raw()
35 game_name = info.get(
"vars")[
"gamename"]
36 if game_name
is None or game_name !=
"gta5":
37 raise InvalidGameNameError
41 """Handle a config flow for FiveM."""
46 self, user_input: dict[str, Any] |
None =
None
47 ) -> ConfigFlowResult:
48 """Handle the initial step."""
49 if user_input
is None:
51 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA
58 except FiveMServerOfflineError:
59 errors[
"base"] =
"cannot_connect"
60 except InvalidGameNameError:
61 errors[
"base"] =
"invalid_game_name"
63 _LOGGER.exception(
"Unexpected exception")
64 errors[
"base"] =
"unknown"
70 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
75 """Handle errors in the game name from the api."""
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)
None validate_input(dict[str, Any] data)