1 """Config flow for Dremel 3D Printer (3D20, 3D40, 3D45)."""
3 from __future__
import annotations
5 from json.decoder
import JSONDecodeError
8 from dremel3dpy
import Dremel3DPrinter
9 from requests.exceptions
import ConnectTimeout, HTTPError
10 import voluptuous
as vol
16 from .const
import DOMAIN, LOGGER
20 return vol.Schema({vol.Required(CONF_HOST, default=host): cv.string})
24 """Handle a config flow for Dremel 3D Printer."""
29 self, user_input: dict[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """Handle the initial step."""
34 if user_input
is None:
39 host = user_input[CONF_HOST]
42 api = await self.hass.async_add_executor_job(Dremel3DPrinter, host)
43 except (ConnectTimeout, HTTPError, JSONDecodeError):
44 errors = {
"base":
"cannot_connect"}
46 LOGGER.exception(
"An unknown error has occurred")
47 errors = {
"base":
"unknown"}
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)
_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)
vol.Schema _schema_with_defaults(str host="")