1 """Config flow for Epic Games Store integration."""
3 from __future__
import annotations
8 from epicstore_api
import EpicGamesStoreAPI
9 import voluptuous
as vol
11 from homeassistant
import config_entries
18 LanguageSelectorConfig,
21 from .const
import DOMAIN, SUPPORTED_LANGUAGES
23 _LOGGER = logging.getLogger(__name__)
25 STEP_USER_DATA_SCHEMA = vol.Schema(
36 """Get default language code based on Home Assistant config."""
37 language_code = f
"{hass.config.language}-{hass.config.country}"
38 if language_code
in SUPPORTED_LANGUAGES:
40 if hass.config.language
in SUPPORTED_LANGUAGES:
41 return hass.config.language
45 async
def validate_input(hass: HomeAssistant, user_input: dict[str, Any]) ->
None:
46 """Validate the user input allows us to connect."""
47 api = EpicGamesStoreAPI(user_input[CONF_LANGUAGE], user_input[CONF_COUNTRY])
48 data = await hass.async_add_executor_job(api.get_free_games)
50 if data.get(
"errors"):
51 _LOGGER.warning(data[
"errors"])
53 assert data[
"data"][
"Catalog"][
"searchStore"][
"elements"]
57 """Handle a config flow for Epic Games Store."""
62 self, user_input: dict[str, Any] |
None =
None
63 ) -> ConfigFlowResult:
64 """Handle the initial step."""
66 STEP_USER_DATA_SCHEMA,
70 CONF_COUNTRY: self.hass.config.country,
73 if user_input
is None:
77 f
"freegames-{user_input[CONF_LANGUAGE]}-{user_input[CONF_COUNTRY]}"
86 _LOGGER.exception(
"Unexpected exception")
87 errors[
"base"] =
"unknown"
90 title=f
"Epic Games Store - Free Games ({user_input[CONF_LANGUAGE]}-{user_input[CONF_COUNTRY]})",
95 step_id=
"user", data_schema=data_schema, errors=errors
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
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_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)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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(HomeAssistant hass, dict[str, Any] user_input)
str|None get_default_language(HomeAssistant hass)