1 """Config flow for Google Maps Travel Time integration."""
3 from __future__
import annotations
7 import voluptuous
as vol
38 CONF_TRANSIT_ROUTING_PREFERENCE,
52 from .helpers
import InvalidApiKeyException, UnknownException, validate_config_entry
54 RECONFIGURE_SCHEMA = vol.Schema(
56 vol.Required(CONF_API_KEY): cv.string,
57 vol.Required(CONF_DESTINATION): cv.string,
58 vol.Required(CONF_ORIGIN): cv.string,
62 CONFIG_SCHEMA = RECONFIGURE_SCHEMA.extend(
64 vol.Required(CONF_NAME, default=DEFAULT_NAME): cv.string,
68 OPTIONS_SCHEMA = vol.Schema(
74 mode=SelectSelectorMode.DROPDOWN,
75 translation_key=CONF_MODE,
80 options=sorted(ALL_LANGUAGES),
81 mode=SelectSelectorMode.DROPDOWN,
82 translation_key=CONF_LANGUAGE,
87 options=AVOID_OPTIONS,
89 mode=SelectSelectorMode.DROPDOWN,
90 translation_key=CONF_AVOID,
97 mode=SelectSelectorMode.DROPDOWN,
98 translation_key=CONF_UNITS,
105 mode=SelectSelectorMode.DROPDOWN,
106 translation_key=CONF_TIME_TYPE,
109 vol.Optional(CONF_TIME, default=
""): cv.string,
112 options=TRAFFIC_MODELS,
114 mode=SelectSelectorMode.DROPDOWN,
115 translation_key=CONF_TRAFFIC_MODEL,
120 options=TRANSPORT_TYPES,
122 mode=SelectSelectorMode.DROPDOWN,
123 translation_key=CONF_TRANSIT_MODE,
128 options=TRANSIT_PREFS,
130 mode=SelectSelectorMode.DROPDOWN,
131 translation_key=CONF_TRANSIT_ROUTING_PREFERENCE,
139 """Get the default options."""
141 CONF_MODE:
"driving",
143 UNITS_IMPERIAL
if hass.config.units
is US_CUSTOMARY_SYSTEM
else UNITS_METRIC
149 """Handle an options flow for Google Travel Time."""
152 """Handle the initial step."""
153 if user_input
is not None:
154 time_type = user_input.pop(CONF_TIME_TYPE)
155 if time := user_input.pop(CONF_TIME,
None):
156 if time_type == ARRIVAL_TIME:
157 user_input[CONF_ARRIVAL_TIME] = time
159 user_input[CONF_DEPARTURE_TIME] = time
167 options[CONF_TIME_TYPE] = ARRIVAL_TIME
170 options[CONF_TIME_TYPE] = DEPARTURE_TIME
180 hass: HomeAssistant, user_input: dict[str, Any]
181 ) -> dict[str, str] |
None:
182 """Validate the user input allows us to connect."""
184 await hass.async_add_executor_job(
185 validate_config_entry,
187 user_input[CONF_API_KEY],
188 user_input[CONF_ORIGIN],
189 user_input[CONF_DESTINATION],
191 except InvalidApiKeyException:
192 return {
"base":
"invalid_auth"}
194 return {
"base":
"timeout_connect"}
195 except UnknownException:
196 return {
"base":
"cannot_connect"}
202 """Handle a config flow for Google Maps Travel Time."""
209 config_entry: ConfigEntry,
210 ) -> GoogleOptionsFlow:
211 """Get the options flow for this handler."""
215 """Handle the initial step."""
216 errors: dict[str, str] |
None =
None
217 user_input = user_input
or {}
222 title=user_input.get(CONF_NAME, DEFAULT_NAME),
234 self, user_input: dict[str, Any] |
None =
None
235 ) -> ConfigFlowResult:
236 """Handle reconfiguration."""
237 errors: dict[str, str] |
None =
None
238 if user_input
is not None:
246 step_id=
"reconfigure",
ConfigFlowResult async_step_init(self, user_input=None)
GoogleOptionsFlow async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, 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)
ConfigFlowResult async_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigEntry _get_reconfigure_entry(self)
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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
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)
dict[str, str] default_options(HomeAssistant hass)
dict[str, str]|None validate_input(HomeAssistant hass, dict[str, Any] user_input)