1 """Config flow for the Cert Expiry platform."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 import voluptuous
as vol
14 from .const
import DEFAULT_PORT, DOMAIN
21 from .helper
import get_cert_expiry_timestamp
23 _LOGGER = logging.getLogger(__name__)
27 """Handle a config flow."""
32 """Initialize the config flow."""
33 self.
_errors_errors: dict[str, str] = {}
37 user_input: Mapping[str, Any],
39 """Test connection to the server and try to get the certificate."""
43 user_input[CONF_HOST],
44 user_input.get(CONF_PORT, DEFAULT_PORT),
47 self.
_errors_errors[CONF_HOST] =
"resolve_failed"
48 except ConnectionTimeout:
49 self.
_errors_errors[CONF_HOST] =
"connection_timeout"
50 except ConnectionRefused:
51 self.
_errors_errors[CONF_HOST] =
"connection_refused"
52 except ValidationFailure:
60 user_input: Mapping[str, Any] |
None =
None,
61 ) -> ConfigFlowResult:
62 """Step when user initializes a integration."""
64 if user_input
is not None:
65 host = user_input[CONF_HOST]
66 port = user_input.get(CONF_PORT, DEFAULT_PORT)
71 title_port = f
":{port}" if port != DEFAULT_PORT
else ""
72 title = f
"{host}{title_port}"
75 data={CONF_HOST: host, CONF_PORT: port},
77 if self.context[
"source"] == SOURCE_IMPORT:
78 _LOGGER.error(
"Config import failed for %s", user_input[CONF_HOST])
82 user_input[CONF_HOST] =
""
83 user_input[CONF_PORT] = DEFAULT_PORT
87 data_schema=vol.Schema(
89 vol.Required(CONF_HOST, default=user_input[CONF_HOST]): str,
91 CONF_PORT, default=user_input.get(CONF_PORT, DEFAULT_PORT)
99 """Import a config entry.
101 Only host was required in the yaml file all other fields are optional
ConfigFlowResult async_step_user(self, Mapping[str, Any]|None user_input=None)
bool _test_connection(self, Mapping[str, Any] user_input)
ConfigFlowResult async_step_import(self, dict[str, Any] import_data)
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_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
datetime.datetime get_cert_expiry_timestamp(HomeAssistant hass, str hostname, int port)