1 """Config flow for Traccar Server integration."""
3 from __future__
import annotations
7 from pytraccar
import ApiClient, ServerModel, TraccarException
8 import voluptuous
as vol
10 from homeassistant
import config_entries
24 SchemaOptionsFlowHandler,
28 BooleanSelectorConfig,
41 CONF_CUSTOM_ATTRIBUTES,
44 CONF_SKIP_ACCURACY_FILTER_FOR,
50 STEP_USER_DATA_SCHEMA = vol.Schema(
77 mode=NumberSelectorMode.BOX,
83 mode=SelectSelectorMode.DROPDOWN,
90 vol.Optional(CONF_SKIP_ACCURACY_FILTER_FOR, default=[]):
SelectSelector(
92 mode=SelectSelectorMode.DROPDOWN,
101 mode=SelectSelectorMode.DROPDOWN,
105 options=
list(EVENTS),
115 """Handle a config flow for Traccar Server."""
118 """Get server info."""
121 host=user_input[CONF_HOST],
122 port=user_input[CONF_PORT],
123 username=user_input[CONF_USERNAME],
124 password=user_input[CONF_PASSWORD],
125 ssl=user_input[CONF_SSL],
126 verify_ssl=user_input[CONF_VERIFY_SSL],
128 return await client.get_server()
132 user_input: dict[str, Any] |
None =
None,
133 ) -> ConfigFlowResult:
134 """Handle the initial step."""
135 errors: dict[str, str] = {}
136 if user_input
is not None:
139 CONF_HOST: user_input[CONF_HOST],
140 CONF_PORT: user_input[CONF_PORT],
145 except TraccarException
as exception:
146 LOGGER.error(
"Unable to connect to Traccar Server: %s", exception)
147 errors[
"base"] =
"cannot_connect"
149 LOGGER.exception(
"Unexpected exception")
150 errors[
"base"] =
"unknown"
153 title=f
"{user_input[CONF_HOST]}:{user_input[CONF_PORT]}",
159 data_schema=STEP_USER_DATA_SCHEMA,
166 config_entry: config_entries.ConfigEntry,
167 ) -> SchemaOptionsFlowHandler:
168 """Get the options flow for this handler."""
ServerModel _get_server_info(self, dict[str, Any] user_input)
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)
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)
OptionsFlow async_get_options_flow(ConfigEntry config_entry)
_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)
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)