1 """Config flow for GPSD integration."""
3 from __future__
import annotations
8 from gps3.agps3threaded
import GPSD_PORT
as DEFAULT_PORT, HOST
as DEFAULT_HOST
9 import voluptuous
as vol
15 from .const
import DOMAIN
17 STEP_USER_DATA_SCHEMA = vol.Schema(
19 vol.Optional(CONF_HOST, default=DEFAULT_HOST): str,
20 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
26 """Handle a config flow for GPSD."""
32 """Test socket connection."""
34 with socket.socket(socket.AF_INET, socket.SOCK_STREAM)
as sock:
35 sock.connect((host, port))
43 self, user_input: dict[str, Any] |
None =
None
44 ) -> ConfigFlowResult:
45 """Handle the initial step."""
46 if user_input
is not None:
49 connected = await self.hass.async_add_executor_job(
50 self.
test_connectiontest_connection, user_input[CONF_HOST], user_input[CONF_PORT]
57 if user_input[CONF_PORT] != DEFAULT_PORT:
58 port = f
":{user_input[CONF_PORT]}"
61 title=user_input.get(CONF_NAME, f
"GPS {user_input[CONF_HOST]}{port}"),
bool test_connection(str host, int port)
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)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)