1 """Config flow for Tesla Wall Connector integration."""
3 from __future__
import annotations
8 from tesla_wall_connector
import WallConnector
9 from tesla_wall_connector.exceptions
import WallConnectorError
10 import voluptuous
as vol
18 from .const
import DOMAIN, WALLCONNECTOR_DEVICE_NAME, WALLCONNECTOR_SERIAL_NUMBER
20 _LOGGER = logging.getLogger(__name__)
23 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
24 """Validate the user input allows us to connect.
26 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
28 wall_connector = WallConnector(
32 version = await wall_connector.async_get_version()
35 "title": WALLCONNECTOR_DEVICE_NAME,
36 WALLCONNECTOR_SERIAL_NUMBER: version.serial_number,
41 """Handle a config flow for Tesla Wall Connector."""
46 """Initialize config flow."""
51 self, discovery_info: dhcp.DhcpServiceInfo
52 ) -> ConfigFlowResult:
53 """Handle dhcp discovery."""
55 _LOGGER.debug(
"Discovered Tesla Wall Connector at [%s]", self.
ip_addressip_address)
60 wall_connector = WallConnector(
63 version = await wall_connector.async_get_version()
64 except WallConnectorError
as ex:
66 "Could not read serial number from Tesla WallConnector at [%s]: [%s]",
72 serial_number: str = version.serial_number
78 "No entry found for wall connector with IP %s. Serial nr: %s",
83 self.context[
"title_placeholders"] = {
85 WALLCONNECTOR_SERIAL_NUMBER: serial_number,
90 self, user_input: dict[str, Any] |
None =
None
91 ) -> ConfigFlowResult:
92 """Handle the initial step."""
93 data_schema = vol.Schema(
94 {vol.Required(CONF_HOST, default=self.
ip_addressip_address): str}
96 if user_input
is None:
102 except WallConnectorError:
103 errors[
"base"] =
"cannot_connect"
105 _LOGGER.exception(
"Unexpected exception")
106 errors[
"base"] =
"unknown"
110 unique_id=info[WALLCONNECTOR_SERIAL_NUMBER], raise_on_progress=
True
113 updates=user_input, reload_on_update=
True
119 step_id=
"user", data_schema=data_schema, errors=errors
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
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)
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)
dict[str, Any] validate_input(HomeAssistant hass, dict[str, Any] data)
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)